-
Notifications
You must be signed in to change notification settings - Fork 0
Test/pr wire #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Test/pr wire #21
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d157665
chore: notify n8n on workflow completion
div0rce 384e772
test: centralize test runner scopes
div0rce 8cc759a
fix: partition full test runner lanes
div0rce 5e24a91
test: enforce test runner ownership
div0rce d791464
ci(workflow): remove direct runtime test steps from ci.yml
div0rce 3e6697f
scripts(package): add new check scripts for static and runtime verifi…
div0rce b217a3c
guardrails(ci-coverage): enhance ci guardrail coverage with script ch…
div0rce b21912a
guardrails(ci-check): update ci must run check to enforce single runt…
div0rce 5b67796
tests(fixtures): update ci must run check test fixtures for new logic
div0rce f4f7c7c
tests(guardrails): update ci must run check tests for new assertions
div0rce b22b2d5
docs(pr-template): update pull request template with new health gates
div0rce 8dfa940
docs(agents): update agents guide with new pr checklist and proofs
div0rce 6d5e441
docs(readme): update health gates section with new verification commands
div0rce 8bce30e
docs(ci-guardrails): update ci and guardrails documentation for new c…
div0rce 544cf47
docs(guardrails): update guardrails doc with new ci and runtime rules
div0rce c8a0e62
docs(script-standards): update script standards for new ci entrypoints
div0rce 0c0071d
audit(full-checkout): update audit script with new ci and test partit…
div0rce 29e5c7d
test: trigger cherry automation forbidden guard
div0rce 2a8eef6
test: trigger cherry automation
div0rce 0965af6
test: retrigger cherry status checks
div0rce 6aba0ad
test: retrigger cherry n8n routing
div0rce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: Notify n8n | ||
|
|
||
| on: | ||
| workflow_run: | ||
| workflows: | ||
| - CI | ||
| types: | ||
| - completed | ||
|
|
||
| jobs: | ||
| notify-n8n: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Send workflow result to n8n | ||
| env: | ||
| N8N_WEBHOOK_URL: ${{ secrets.N8N_WEBHOOK_URL }} | ||
| N8N_WEBHOOK_TOKEN: ${{ secrets.N8N_WEBHOOK_TOKEN }} | ||
| run: | | ||
| curl -X POST "$N8N_WEBHOOK_URL" \ | ||
| -H "Authorization: Bearer $N8N_WEBHOOK_TOKEN" \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "event": "github.workflow.completed", | ||
| "repo": "${{ github.repository }}", | ||
| "workflow": "${{ github.event.workflow_run.name }}", | ||
| "status": "${{ github.event.workflow_run.conclusion }}", | ||
| "branch": "${{ github.event.workflow_run.head_branch }}", | ||
| "sha": "${{ github.event.workflow_run.head_sha }}", | ||
| "url": "${{ github.event.workflow_run.html_url }}" | ||
| }' | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import type { NextRequest } from 'next/server'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { getStandardBearerHeader } from '../../../lib/http/bearer-token.js'; | ||
|
|
||
| export type AutomationAuthResult = { ok: true } | { ok: false; response: NextResponse }; | ||
|
|
||
| export function requireAutomationToken(request: NextRequest): AutomationAuthResult { | ||
| const expected = process.env['CHERRY_AUTOMATION_TOKEN']; | ||
| if (typeof expected !== 'string' || expected.trim().length === 0) { | ||
| return { | ||
| ok: false, | ||
| response: NextResponse.json( | ||
| { error: 'automation_token_not_configured' }, | ||
| { status: 503 } | ||
| ), | ||
| }; | ||
| } | ||
|
|
||
| const bearerHeader = getStandardBearerHeader(request.headers); | ||
| const headerToken = request.headers.get('x-cherry-automation-token'); | ||
| const bearerToken = | ||
| bearerHeader !== null && bearerHeader.startsWith('Bearer ') | ||
| ? bearerHeader.slice('Bearer '.length) | ||
| : null; | ||
| const provided = bearerToken ?? headerToken; | ||
| if (provided !== expected) { | ||
| return { | ||
| ok: false, | ||
| response: NextResponse.json({ error: 'Unauthorized' }, { status: 401 }), | ||
| }; | ||
| } | ||
|
|
||
| return { ok: true }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { NextRequest } from 'next/server'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { | ||
| AutomationEventIdempotencyConflictError, | ||
| classifyAndStorePrAutomation, | ||
| } from '../../../../../lib/automation/events.js'; | ||
| import { ensureRouteConfigFromEnv } from '../../../../../lib/config/route.js'; | ||
| import { PrAutomationClassifySchema } from '../../../../../lib/schemas/automation.js'; | ||
| import { parseJsonBody } from '../../../../../lib/validation.js'; | ||
| import { requireAutomationToken } from '../../_auth.js'; | ||
|
|
||
| export async function POST(request: NextRequest): Promise<NextResponse> { | ||
| ensureRouteConfigFromEnv(process.env); | ||
|
|
||
| const auth = requireAutomationToken(request); | ||
| if (auth.ok === false) return auth.response; | ||
|
|
||
| const parsed = await parseJsonBody(request, PrAutomationClassifySchema); | ||
| if (parsed.ok === false) return parsed.response; | ||
|
|
||
| let result: Awaited<ReturnType<typeof classifyAndStorePrAutomation>>; | ||
| try { | ||
| result = await classifyAndStorePrAutomation(parsed.data); | ||
| } catch (error: unknown) { | ||
| if (error instanceof AutomationEventIdempotencyConflictError) { | ||
| return NextResponse.json( | ||
| { error: 'automation_event_idempotency_conflict' }, | ||
| { status: 409 } | ||
| ); | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| ok: true, | ||
| created: result.created, | ||
| automationEventId: result.event.id, | ||
| outputHash: result.event.outputHash, | ||
| classifierOutput: result.classifierOutput, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import type { NextRequest } from 'next/server'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { AutomationEventIngestSchema } from '../../../../lib/schemas/automation.js'; | ||
| import { | ||
| AutomationEventIdempotencyConflictError, | ||
| storeAutomationEvent, | ||
| } from '../../../../lib/automation/events.js'; | ||
| import { ensureRouteConfigFromEnv } from '../../../../lib/config/route.js'; | ||
| import { parseJsonBody } from '../../../../lib/validation.js'; | ||
| import { requireAutomationToken } from '../_auth.js'; | ||
|
|
||
| export async function POST(request: NextRequest): Promise<NextResponse> { | ||
| ensureRouteConfigFromEnv(process.env); | ||
|
|
||
| const auth = requireAutomationToken(request); | ||
| if (auth.ok === false) return auth.response; | ||
|
|
||
| const parsed = await parseJsonBody(request, AutomationEventIngestSchema); | ||
| if (parsed.ok === false) return parsed.response; | ||
|
|
||
| let result: Awaited<ReturnType<typeof storeAutomationEvent>>; | ||
| try { | ||
| result = await storeAutomationEvent(parsed.data); | ||
| } catch (error: unknown) { | ||
| if (error instanceof AutomationEventIdempotencyConflictError) { | ||
| return NextResponse.json( | ||
| { error: 'automation_event_idempotency_conflict' }, | ||
| { status: 409 } | ||
| ); | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| ok: true, | ||
| created: result.created, | ||
| automationEventId: result.event.id, | ||
| outputHash: result.event.outputHash, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type { NextRequest } from 'next/server'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { replayAutomationEvent } from '../../../../lib/automation/events.js'; | ||
| import { ensureRouteConfigFromEnv } from '../../../../lib/config/route.js'; | ||
| import { AutomationReplaySchema } from '../../../../lib/schemas/automation.js'; | ||
| import { parseJsonBody } from '../../../../lib/validation.js'; | ||
| import { requireAutomationToken } from '../_auth.js'; | ||
|
|
||
| export async function POST(request: NextRequest): Promise<NextResponse> { | ||
| ensureRouteConfigFromEnv(process.env); | ||
|
|
||
| const auth = requireAutomationToken(request); | ||
| if (auth.ok === false) return auth.response; | ||
|
|
||
| const parsed = await parseJsonBody(request, AutomationReplaySchema); | ||
| if (parsed.ok === false) return parsed.response; | ||
|
|
||
| const result = await replayAutomationEvent( | ||
| parsed.data.automationEventId, | ||
| parsed.data.classifierVersion | ||
| ); | ||
| if (result === null) { | ||
| return NextResponse.json({ error: 'automation_event_not_found' }, { status: 404 }); | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| ok: true, | ||
| automationEventId: result.event.id, | ||
| outputHash: result.outputHash, | ||
| matches: result.matches, | ||
| reason: result.reason, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import type { NextRequest } from 'next/server'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { | ||
| SimulationSnapshotIdempotencyConflictError, | ||
| compareAndStoreSimulationSnapshot, | ||
| } from '../../../../../lib/automation/events.js'; | ||
| import { ensureRouteConfigFromEnv } from '../../../../../lib/config/route.js'; | ||
| import { SimulationSnapshotCompareSchema } from '../../../../../lib/schemas/automation.js'; | ||
| import { parseJsonBody } from '../../../../../lib/validation.js'; | ||
| import { requireAutomationToken } from '../../_auth.js'; | ||
|
|
||
| export async function POST(request: NextRequest): Promise<NextResponse> { | ||
| ensureRouteConfigFromEnv(process.env); | ||
|
|
||
| const auth = requireAutomationToken(request); | ||
| if (auth.ok === false) return auth.response; | ||
|
|
||
| const parsed = await parseJsonBody(request, SimulationSnapshotCompareSchema); | ||
| if (parsed.ok === false) return parsed.response; | ||
|
|
||
| let result: Awaited<ReturnType<typeof compareAndStoreSimulationSnapshot>>; | ||
| try { | ||
| result = await compareAndStoreSimulationSnapshot(parsed.data); | ||
| } catch (error: unknown) { | ||
| if (error instanceof SimulationSnapshotIdempotencyConflictError) { | ||
| return NextResponse.json( | ||
| { error: 'simulation_snapshot_idempotency_conflict' }, | ||
| { status: 409 } | ||
| ); | ||
| } | ||
| throw error; | ||
| } | ||
|
|
||
| return NextResponse.json({ | ||
| ok: true, | ||
| created: result.created, | ||
| snapshotId: result.snapshot.id, | ||
| outputHash: result.snapshot.outputHash, | ||
| comparisonOutput: result.comparisonOutput, | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import type { NextRequest } from 'next/server'; | ||
| import { NextResponse } from 'next/server'; | ||
| import { | ||
| GithubStatusRetryNotFoundError, | ||
| retryGithubStatus, | ||
| } from '../../../../../../lib/automation/github-status.js'; | ||
| import { ensureRouteConfigFromEnv } from '../../../../../../lib/config/route.js'; | ||
| import { GithubStatusRetrySchema } from '../../../../../../lib/schemas/automation.js'; | ||
| import { parseJsonBody } from '../../../../../../lib/validation.js'; | ||
| import { requireAutomationToken } from '../../../_auth.js'; | ||
|
|
||
| export async function POST(request: NextRequest): Promise<NextResponse> { | ||
| ensureRouteConfigFromEnv(process.env); | ||
|
|
||
| const auth = requireAutomationToken(request); | ||
| if (auth.ok === false) return auth.response; | ||
|
|
||
| const parsed = await parseJsonBody(request, GithubStatusRetrySchema); | ||
| if (parsed.ok === false) return parsed.response; | ||
|
|
||
| try { | ||
| const result = await retryGithubStatus(parsed.data, { | ||
| githubToken: process.env['GITHUB_TOKEN'] ?? '', | ||
| }); | ||
| return NextResponse.json({ | ||
| ok: true, | ||
| retried: result.retried, | ||
| statusCheck: result.statusCheck, | ||
| }); | ||
| } catch (error: unknown) { | ||
| if (error instanceof GithubStatusRetryNotFoundError) { | ||
| return NextResponse.json({ error: 'github_status_not_found' }, { status: 404 }); | ||
| } | ||
| const statusCheck = (error as { statusCheck?: unknown }).statusCheck; | ||
| const message = error instanceof Error ? error.message : 'github_status_retry_failed'; | ||
| const status = /forbidden Cherry finance endpoint|Unsupported GitHub status context/.test( | ||
| message | ||
| ) | ||
| ? 400 | ||
| : 502; | ||
| return NextResponse.json( | ||
| { | ||
| ok: false, | ||
| error: message, | ||
| statusCheck, | ||
| }, | ||
| { status } | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
workflow_run.workflowsis configured asCI, but this repo’s CI workflow is namedciin.github/workflows/ci.yml(name: ci). Because this filter matches workflow names, the notifier job will never run after CI completions, so n8n will miss all intended events.Useful? React with 👍 / 👎.