Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
176 changes: 120 additions & 56 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,123 @@
<p align="center"><a href="https://laravel.com" target="_blank"><img src="https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg" width="400" alt="Laravel Logo"></a></p>

<p align="center">
<a href="https://github.com/laravel/framework/actions"><img src="https://github.com/laravel/framework/workflows/tests/badge.svg" alt="Build Status"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/dt/laravel/framework" alt="Total Downloads"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/v/laravel/framework" alt="Latest Stable Version"></a>
<a href="https://packagist.org/packages/laravel/framework"><img src="https://img.shields.io/packagist/l/laravel/framework" alt="License"></a>
</p>

## About Laravel

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

- [Simple, fast routing engine](https://laravel.com/docs/routing).
- [Powerful dependency injection container](https://laravel.com/docs/container).
- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage.
- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent).
- Database agnostic [schema migrations](https://laravel.com/docs/migrations).
- [Robust background job processing](https://laravel.com/docs/queues).
- [Real-time event broadcasting](https://laravel.com/docs/broadcasting).

Laravel is accessible, powerful, and provides tools required for large, robust applications.

## Learning Laravel

Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. You can also check out [Laravel Learn](https://laravel.com/learn), where you will be guided through building a modern Laravel application.

If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains thousands of video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library.

## Laravel Sponsors

We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the [Laravel Partners program](https://partners.laravel.com).

### Premium Partners

- **[Vehikl](https://vehikl.com)**
- **[Tighten Co.](https://tighten.co)**
- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)**
- **[64 Robots](https://64robots.com)**
- **[Curotec](https://www.curotec.com/services/technologies/laravel)**
- **[DevSquad](https://devsquad.com/hire-laravel-developers)**
- **[Redberry](https://redberry.international/laravel-development)**
- **[Active Logic](https://activelogic.com)**

## Contributing

Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions).

## Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct).

## Security Vulnerabilities

If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed.
# Synapse Sentinel Core

Event intake system for Synapse Sentinel. Receives certification results from gate workflows and stores them as events using Laravel Verbs.

## Architecture

```
Gate Workflow → POST /api/webhooks/gate → Core
↓ stores events
Laravel Verbs
↓ projects to
CertificationState
```

## Installation

```bash
composer install
cp .env.example .env
php artisan key:generate
php artisan migrate
```

## Webhook Endpoint

### POST /api/webhooks/gate

Receives certification results from gate workflows.

**Headers:**
- `Content-Type: application/json`
- `X-Gate-Signature: <hmac-sha256>` (optional, required if `GATE_WEBHOOK_SECRET` is set)

**Request Body:**
```json
{
"repository": "synapse-sentinel/core",
"sha": "abc123def456",
"verdict": "approved",
"reason": "All checks passed",
"checks": {
"tests": {"status": "pass", "coverage": 100},
"security": {"status": "pass"},
"syntax": {"status": "pass"}
},
"triggered_by": "pull_request",
"pr_number": 42
}
```

**Response:**
```json
{"message": "ok"}
```

## Event Schema

### CertificationRequested

Fired when a certification process begins.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `repository` | string | yes | Full repository name (e.g., `owner/repo`) |
| `sha` | string | yes | Git commit SHA |
| `triggeredBy` | string | yes | What triggered the certification (`push`, `pull_request`, `workflow_dispatch`) |
| `prNumber` | int | no | Pull request number if triggered by PR |
| `branch` | string | no | Branch name |

### CertificationCompleted

Fired when certification finishes with a verdict.

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `repository` | string | yes | Full repository name |
| `sha` | string | yes | Git commit SHA |
| `verdict` | string | yes | Result: `approved`, `rejected`, or `escalate` |
| `reason` | string | no | Human-readable explanation |
| `checks` | object | no | Detailed check results |
| `triggeredBy` | string | no | What triggered the certification |
| `prNumber` | int | no | Pull request number |

### CertificationFailed

Fired when certification encounters an error (distinct from rejection).

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `repository` | string | yes | Full repository name |
| `sha` | string | yes | Git commit SHA |
| `error` | string | yes | Error message |
| `stage` | string | no | Which stage failed (`tests`, `build`, `security`) |
| `context` | object | no | Additional error context |

## State Projection

Events are projected to `CertificationState` which tracks:

- `status`: `pending`, `completed`, or `failed`
- `verdict`: `approved`, `rejected`, or `escalate` (when completed)
- `repository`, `sha`, `branch`, `pr_number`
- Timestamps: `requested_at`, `completed_at`, `failed_at`

Query state:
```php
$state = CertificationState::load($certification_id);
$state->isApproved(); // bool
$state->isRejected(); // bool
$state->isPending(); // bool
$state->isFailed(); // bool
```

## Testing

```bash
php artisan test
php artisan test --coverage
```

## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
GPL-3.0-or-later
19 changes: 19 additions & 0 deletions app/Events/CertificationCompleted.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@

namespace App\Events;

use App\States\CertificationState;
use Carbon\CarbonImmutable;
use Thunk\Verbs\Attributes\Autodiscovery\StateId;
use Thunk\Verbs\Event;

class CertificationCompleted extends Event
{
#[StateId(CertificationState::class)]
public ?int $certification_id = null;

public function __construct(
public string $repository,
public string $sha,
Expand All @@ -17,4 +23,17 @@ public function __construct(
public ?string $triggeredBy = null,
public ?int $prNumber = null,
) {}

public function apply(CertificationState $state): void
{
$state->repository = $this->repository;
$state->sha = $this->sha;
$state->status = 'completed';
$state->verdict = $this->verdict;
$state->reason = $this->reason;
$state->checks = $this->checks;
$state->triggered_by = $this->triggeredBy;
$state->pr_number = $this->prNumber;
$state->completed_at = CarbonImmutable::now();
}
}
31 changes: 31 additions & 0 deletions app/Events/CertificationFailed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Events;

use App\States\CertificationState;
use Carbon\CarbonImmutable;
use Thunk\Verbs\Attributes\Autodiscovery\StateId;
use Thunk\Verbs\Event;

class CertificationFailed extends Event
{
#[StateId(CertificationState::class)]
public ?int $certification_id = null;

public function __construct(
public string $repository,
public string $sha,
public string $error,
public ?string $stage = null,
public ?array $context = null,
) {}

public function apply(CertificationState $state): void
{
$state->status = 'failed';
$state->error = $this->error;
$state->failed_at = CarbonImmutable::now();
}
}
35 changes: 35 additions & 0 deletions app/Events/CertificationRequested.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace App\Events;

use App\States\CertificationState;
use Carbon\CarbonImmutable;
use Thunk\Verbs\Attributes\Autodiscovery\StateId;
use Thunk\Verbs\Event;

class CertificationRequested extends Event
{
#[StateId(CertificationState::class)]
public ?int $certification_id = null;

public function __construct(
public string $repository,
public string $sha,
public string $triggeredBy,
public ?int $prNumber = null,
public ?string $branch = null,
) {}

public function apply(CertificationState $state): void
{
$state->repository = $this->repository;
$state->sha = $this->sha;
$state->triggered_by = $this->triggeredBy;
$state->pr_number = $this->prNumber;
$state->branch = $this->branch;
$state->status = 'pending';
$state->requested_at = CarbonImmutable::now();
}
}
62 changes: 62 additions & 0 deletions app/States/CertificationState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace App\States;

use Carbon\CarbonImmutable;
use Thunk\Verbs\State;

class CertificationState extends State
{
public string $repository = '';

public string $sha = '';

public string $status = 'pending';

public ?string $verdict = null;

public ?string $reason = null;

public ?string $error = null;

public ?string $triggered_by = null;

public ?int $pr_number = null;

public ?string $branch = null;

public ?array $checks = null;

public ?CarbonImmutable $requested_at = null;

public ?CarbonImmutable $completed_at = null;

public ?CarbonImmutable $failed_at = null;

public function isPending(): bool
{
return $this->status === 'pending';
}

public function isCompleted(): bool
{
return $this->status === 'completed';
}

public function isFailed(): bool
{
return $this->status === 'failed';
}

public function isApproved(): bool
{
return $this->isCompleted() && $this->verdict === 'approved';
}

public function isRejected(): bool
{
return $this->isCompleted() && $this->verdict === 'rejected';
}
}
Loading