Repository navigation
feat: complete fail-closed OC evidence Gate 1 #29
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
Merged
Merged
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aaf19ac
feat: define fail-closed OC evidence
Adaptive-Liquidity b5ba665
feat: complete OC evidence Gate 1
Adaptive-Liquidity 9cdeb5d
fix: address OC evidence verification gaps
Adaptive-Liquidity a29fbe0
Potential fix for pull request finding
Adaptive-Liquidity eacd632
Potential fix for pull request finding
Adaptive-Liquidity bcd3f7c
fix: require capsule_id for OC_FULFILLED and repair db.ts transaction…
Copilot da92404
test: cover oc lifecycle advance chain and competing terminal writes
Copilot 3333d36
Update src/lib/db.ts
Adaptive-Liquidity 66e9c38
fix: validate durable OC evidence against persisted subject binding
Copilot 88958b4
fix: repair pg transaction rollback cleanup
Adaptive-Liquidity 2de9bac
chore: apply Prettier to fix format:check in CI
Adaptive-Liquidity 6b6679f
fix: preserve sparse array hash semantics
Adaptive-Liquidity 152b7ee
chore: require Node 22.6+ for npm test
Adaptive-Liquidity 7fec419
fix: pin Node 22.12.0 for Vite 8.2.1 engine requirement
Adaptive-Liquidity 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| -- S2 Gate 1: durable Outcome Contract lifecycle and transactional delivery outbox. | ||
| -- Hall remains closed; pending rows have no sender until the upstream decoder is live. | ||
|
|
||
| create table if not exists oc_lifecycle ( | ||
| contract_id text primary key, | ||
| latest_event_id text, | ||
| cluster_id text, | ||
| cluster_slug text, | ||
| subject text, | ||
| current_type text check ( | ||
| current_type is null or current_type in ( | ||
| 'OC_OPENED', 'OC_AWARDED', 'OC_FULFILLED', 'OC_FAILED', 'OC_SLASHED' | ||
| ) | ||
| ), | ||
| current_occurred_at timestamptz, | ||
| updated_at timestamptz not null default now() | ||
| ); | ||
|
|
||
| create table if not exists oc_evidence_events ( | ||
| event_id text primary key, | ||
| idempotency_key text not null, | ||
| contract_id text not null, | ||
| cluster_id text not null, | ||
| cluster_slug text not null, | ||
| subject text not null, | ||
| type text not null check ( | ||
| type in ('OC_OPENED', 'OC_AWARDED', 'OC_FULFILLED', 'OC_FAILED', 'OC_SLASHED') | ||
| ), | ||
| occurred_at timestamptz not null, | ||
| evidence_hash text not null, | ||
| capsule_id text, | ||
| payload jsonb not null, | ||
| created_at timestamptz not null default now(), | ||
| unique (contract_id, type, idempotency_key) | ||
| ); | ||
|
|
||
| alter table oc_lifecycle | ||
| drop constraint if exists oc_lifecycle_latest_event_id_fkey; | ||
| alter table oc_lifecycle | ||
| add constraint oc_lifecycle_latest_event_id_fkey | ||
| foreign key (latest_event_id) references oc_evidence_events (event_id); | ||
|
|
||
| create index if not exists oc_evidence_events_contract_id_idx | ||
| on oc_evidence_events (contract_id, occurred_at); | ||
|
|
||
| create table if not exists oc_evidence_outbox ( | ||
| event_id text primary key references oc_evidence_events (event_id) on delete cascade, | ||
| payload jsonb not null, | ||
| status text not null default 'pending' check (status in ('pending', 'sent')), | ||
| attempts integer not null default 0 check (attempts >= 0), | ||
| available_at timestamptz not null default now(), | ||
| created_at timestamptz not null default now(), | ||
| sent_at timestamptz | ||
| ); | ||
|
|
||
| create index if not exists oc_evidence_outbox_pending_idx | ||
| on oc_evidence_outbox (available_at, created_at) | ||
| where status = 'pending'; |
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,27 @@ | ||
| import { readdir } from "node:fs/promises"; | ||
| import { join } from "node:path"; | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| async function collectTests(directory) { | ||
| const tests = []; | ||
| for (const entry of await readdir(directory, { withFileTypes: true })) { | ||
| const path = join(directory, entry.name); | ||
| if (entry.isDirectory()) { | ||
| tests.push(...(await collectTests(path))); | ||
| } else if (entry.name.endsWith(".test.mjs") || entry.name.endsWith(".test.ts")) { | ||
| tests.push(path); | ||
| } | ||
| } | ||
| return tests; | ||
| } | ||
|
|
||
| const testFiles = (await Promise.all(["scripts", "src"].map(collectTests))).flat().sort(); | ||
| if (testFiles.length === 0) { | ||
| throw new Error("No test files found"); | ||
| } | ||
|
|
||
| const result = spawnSync(process.execPath, ["--experimental-strip-types", "--test", ...testFiles], { | ||
| stdio: "inherit", | ||
| }); | ||
| if (result.error) throw result.error; | ||
| process.exitCode = result.status ?? 1; | ||
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,25 @@ | ||
| export function canonicalJsonStringify(value: unknown): string { | ||
| return stringify(value); | ||
| } | ||
|
|
||
| function stringify(value: unknown): string { | ||
| if (value === null) return "null"; | ||
| if (typeof value === "string") return JSON.stringify(value); | ||
| if (typeof value === "number") return Number.isFinite(value) ? JSON.stringify(value) : "null"; | ||
| if (typeof value === "boolean") return value ? "true" : "false"; | ||
| if (Array.isArray(value)) return `[${value.map(stringify).join(",")}]`; | ||
|
|
||
| if (typeof value === "object") { | ||
| const object = value as Record<string, unknown>; | ||
| const keys = Object.keys(object) | ||
| .filter((key) => object[key] !== undefined) | ||
| .sort(); | ||
| return `{${keys.map((key) => `${JSON.stringify(key)}:${stringify(object[key])}`).join(",")}}`; | ||
| } | ||
| return "null"; | ||
| } | ||
|
|
||
| export async function sha256Hex(input: string | Uint8Array): Promise<string> { | ||
| const bytes = typeof input === "string" ? new TextEncoder().encode(input) : input.slice(); | ||
| const digest = await crypto.subtle.digest("SHA-256", bytes); | ||
| return Array.from(new Uint8Array(digest), (byte) => byte.toString(16).padStart(2, "0")).join(""); | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.