From b7f68909668112748edd2c9b95e23c171193803e Mon Sep 17 00:00:00 2001 From: Hamza Khan <139022998+HKcode22@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:26:46 -0800 Subject: [PATCH 1/5] Real G5A independent GitHub-only read-only 3-horizon source, PRE, POST and bias aggregate verification after frozen W --- ..._independent_real_cohort_readonly_audit.ts | 232 ++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts diff --git a/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts b/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts new file mode 100644 index 000000000..795aafc72 --- /dev/null +++ b/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts @@ -0,0 +1,232 @@ +/** + * Independent G5A Gate5 real cohort audit — READ ONLY, no provider request. + * + * Github 2026-11-05 05:12Z, after frozen W=T_native+2h for the + * 2026-11-05 02:00–03:00Z WSSS population. + * + * Factual, privacy-preserving counts only. Does not read or emit raw FIDS + * Content, flight IDs, credentials, or user data. Does NOT declare science PASS. + * Requires a separate independent audit reader, not the new source writer. + */ +import {readFileSync} from "node:fs"; +import {createHash} from "node:crypto"; +import {execFileSync} from "node:child_process"; +import pg from "pg"; +import { + G5A_POST_AGGREGATE_AUDIT_SQL_V39, + postReservationUuidV39 +} from "./v39_phase4_gate5_g5a_prospective_post_schedule_observation"; + +export const G5A_INDEPENDENT_AUDIT_SCHEMA_V39= + "v39.phase4.g5a-independent-real-source-pre-post-counts.v1" as const; +const REPO="HKcode22/ReplitTranvr"; +const WF="Phase4 Gate5 G5A Independent Cohort Audit (No Provider)"; +const PATH=".github/workflows/phase4-gate5-g5a-independent-final-audit.yml"; +const CRON="12 5 5 11 *"; +const GRID="data-collection/phase4/GATE5_G5A_WSSS_20261105_FROZEN_SOURCE_GRID.json"; +const START=Date.parse("2026-11-05T05:10:00.000Z"); +const END=Date.parse("2026-11-08T00:00:00.000Z"); +const SHA=/^[a-f0-9]{40}$/; +function hold(code:string):never{throw Error("P4_G5_G5A_INDEPENDENT_"+code+"_HOLD")} +const sha=(s:string)=>createHash("sha256").update(s).digest("hex"); +function count(v:unknown){ + const n=Number(v); + if(!Number.isSafeInteger(n)||n<0)hold("NONFINITE_AGGREGATE_COUNT"); + return n; +} +export function requireG5AIndependentAuditContextV39( + e:NodeJS.ProcessEnv,head:string,at:number +){ + if(!SHA.test(head)||!Number.isFinite(at)||at=END|| + e.GITHUB_ACTIONS!=="true"||e.GITHUB_REPOSITORY!==REPO|| + e.GITHUB_REF!=="refs/heads/main"||e.GITHUB_SHA!==head|| + e.GITHUB_RUN_ATTEMPT!=="1"|| + !["schedule","workflow_dispatch"].includes(e.GITHUB_EVENT_NAME??"")|| + e.GITHUB_WORKFLOW!==WF|| + e.GITHUB_WORKFLOW_REF!==REPO+"/"+PATH+"@refs/heads/main"|| + e.GITHUB_JOB!=="audit-independent"|| + (e.GITHUB_EVENT_NAME==="schedule"&&e.GITHUB_EVENT_SCHEDULE!==CRON)|| + !e.GATE05_AUTOMATION_DATABASE_URL|| + !!e.DATABASE_URL||!!e.V39_DATABASE_RUNTIME_URL|| + !!e.P4_G5_SOURCE_OWNER_DATABASE_URL|| + !!e.AERODATABOX_API_KEY||e.ADB_AUTO_COLLECT!=="0"|| + e.V39_PHASE6_PROCESS_ARMED!=="0") + hold("GITHUB_READER_DATE_OR_ISOLATION"); +} +export const G5A_SOURCE_AUDIT_SQL_V39=[ + "SELECT o.horizon,", + "count(DISTINCT q.query_digest)::int planned_slots,", + "count(DISTINCT a.query_digest)::int irrevocably_reserved_slots,", + "count(DISTINCT b.population_query_id)::int exact_original_bound_slots,", + "count(DISTINCT b.population_query_id) FILTER (WHERE", + "s.available_at<=q.prediction_cutoff_utc", + "AND b.original_response_sha256=s.response_hash", + "AND s.raw_expired_at_utc IS NULL)::int bound_source_on_time_at_audit,", + "count(DISTINCT b.population_query_id) FILTER (WHERE", + "b.source_use_expires_at_utc<=clock_timestamp())::int", + "original_use_lifetime_elapsed", + "FROM clean.phase4_g5_fids_physical_owner_v39 o", + "JOIN clean.phase4_g5_fids_allowed_query_v39 q", + "ON q.owner_digest=o.owner_digest", + "LEFT JOIN clean.phase4_g5_fids_physical_attempt_v39 a", + "ON a.query_digest=q.query_digest", + "LEFT JOIN clean.phase4_g5_fids_original_binding_v39 b", + "ON b.expected_reservation_sha256=a.expected_reservation_sha256", + "AND b.manifest_sha256=o.manifest_sha256", + "LEFT JOIN clean.fids_query_response s", + "ON s.population_query_id=b.population_query_id", + "WHERE o.manifest_sha256=$1 AND o.cohort_id IS NULL", + "GROUP BY o.horizon ORDER BY o.horizon" +].join(" "); +export const G5A_PRE_AUDIT_SQL_V39=[ + "SELECT s.horizon,count(*)::int as persisted_pre,", + "count(DISTINCT s.flight_instance_id)::int unique_physical_pre,", + "count(*) FILTER(WHERE s.created_at<=s.prediction_cutoff_utc)::int", + "source_qualified_pre_written_before_cutoff,", + "count(*) FILTER(WHERE s.created_at>s.prediction_cutoff_utc)::int", + "late_pre_written_should_be_zero,", + "count(*) FILTER(WHERE s.fids_response_hash IS NULL)::int", + "missing_pre_source_hash,", + "count(*) FILTER(WHERE s.prediction_state<>'PRE_DEPARTURE')::int", + "not_true_pre,", + "count(*) FILTER(WHERE s.selected_t_version IS NULL)::int", + "native_t_version_unknown", + "FROM clean.flight_snapshots s WHERE s.frame_hash=$1", + "AND s.horizon IN ('T-24h','T-6h','T-90m')", + "GROUP BY s.horizon ORDER BY s.horizon" +].join(" "); +export const G5A_POPULATION_AUDIT_SQL_V39=[ + "SELECT count(*)::int population_rows,", + "count(DISTINCT p.analytic_identity_id) FILTER (WHERE", + "p.codeshare_resolution_status='confirmed_operating_leg'", + "AND p.population_role='requested_airport_primary'", + "AND p.scope_classification='confirmed_core')::int", + "distinct_source_confirmed_operating_leg_ids,", + "count(*) FILTER(WHERE p.codeshare_resolution_status<>", + "'confirmed_operating_leg')::int ambiguous_or_codeshared_rows", + "FROM clean.flight_population p", + "JOIN clean.phase4_g5_fids_original_binding_v39 b", + "ON b.population_query_id=p.population_query_id", + "WHERE b.manifest_sha256=$1" +].join(" "); +export async function main(){ + const e=process.env; + const head=execFileSync("git",["rev-parse","HEAD"],{ + encoding:"utf8",timeout:4000}).trim(); + requireG5AIndependentAuditContextV39(e,head,Date.now()); + const bytes=readFileSync(GRID,"utf8"),manifest=JSON.parse(bytes) as Record; + if(manifest.cohortId!=="WSSS_G5A_20261105_0200Z"|| + bytes!==JSON.stringify(manifest,null,2)+"\n") + hold("MANIFEST_CHANGED_OR_UNREVIEWED"); + const hash=sha(bytes); + const ids=[0,1,2].map(i=>postReservationUuidV39(hash,i)); + const db=new pg.Client({connectionString:e.GATE05_AUTOMATION_DATABASE_URL, + connectionTimeoutMillis:9000,query_timeout:16000, + application_name:"g5a_independent_readonly_counts"}); + await db.connect(); + let tx=false; + try{ + await db.query("BEGIN TRANSACTION ISOLATION LEVEL REPEATABLE READ READ ONLY"); + tx=true; + await db.query("SET LOCAL statement_timeout='15000ms'"); + const tables=await db.query(G5A_SOURCE_AUDIT_SQL_V39,[hash]); + const snapshots=await db.query(G5A_PRE_AUDIT_SQL_V39,[hash]); + const pop=await db.query(G5A_POPULATION_AUDIT_SQL_V39,[hash]); + const post=await db.query(G5A_POST_AGGREGATE_AUDIT_SQL_V39,[hash,ids]); + const budget=await db.query( + "SELECT cohort_id,reserved_units,project_unit_ceiling "+ + "FROM clean.phase4_g5_fids_cohort_budget_v39 "+ + "WHERE manifest_sha256=$1",[hash]); + if(budget.rows.length>1)hold("CONFLICTING_BUDGET"); + const source=tables.rows.map(r=>({ + horizon:String(r.horizon), + plannedSourceSlots:count(r.planned_slots), + actualCommittedPhysicalReservations:count(r.irrevocably_reserved_slots), + originalBoundSlots:count(r.exact_original_bound_slots), + sourceBoundAndOnTimeNow:count(r.bound_source_on_time_at_audit), + sourceLifetimeExpiredByAudit:count(r.original_use_lifetime_elapsed) + })); + const pre=snapshots.rows.map(r=>({ + horizon:String(r.horizon),persistedPRE:count(r.persisted_pre), + distinctOperatingPRE:count(r.unique_physical_pre), + preActuallyCommittedBeforeCutoff:count(r.source_qualified_pre_written_before_cutoff), + latePREInvalid:count(r.late_pre_written_should_be_zero), + missingPreSourceHash:count(r.missing_pre_source_hash), + notTruePRE:count(r.not_true_pre), + missingNativeTVersion:count(r.native_t_version_unknown) + })); + const outcome=post.rows.map(r=>({ + horizon:String(r.horizon),preDenominator:count(r.expected_pre), + asofBaselineSource:count(r.baseline_sourced), + postSourceObservedByW:count(r.post_observed), + observedScheduleRevisionAtLeast15min:count(r.revision_ge15), + observedScheduleRevisionLess15min:count(r.revision_lt15), + missingOrCensored:count(r.expected_pre)-count(r.revision_ge15)- + count(r.revision_lt15) + })); + for(const r of source){ + if(r.plannedSourceSlots!==3|| + r.actualCommittedPhysicalReservations>3|| + r.originalBoundSlots>r.actualCommittedPhysicalReservations|| + r.sourceBoundAndOnTimeNow>r.originalBoundSlots) + hold("SOURCE_AGGREGATE_DRIFT"); + } + for(const r of pre){ + if(r.preActuallyCommittedBeforeCutoff>r.persistedPRE|| + r.distinctOperatingPRE>r.persistedPRE)hold("PRE_AGGREGATE_DRIFT"); + } + for(const r of outcome){ + if(r.postSourceObservedByW>r.preDenominator|| + r.observedScheduleRevisionAtLeast15min+ + r.observedScheduleRevisionLess15min>r.postSourceObservedByW|| + r.missingOrCensored<0) + hold("POST_AGGREGATE_DRIFT"); + } + const b=budget.rows[0]; + const used=b?count(b.reserved_units):0; + const ceiling=b?count(b.project_unit_ceiling):0; + if(used>ceiling||ceiling!==24&&!!b) + hold("PROJECT_UNIT_CEILING_DRIFT"); + const payload={ + schema:G5A_INDEPENDENT_AUDIT_SCHEMA_V39, + status:source.length===3&&budget.rows.length===1? + "INDEPENDENT_COUNTS_COMPLETE_NOT_SCIENCE_VERDICT": + "HOLD_NO_COMPLETE_PROSPECTIVE_THREE_HORIZON_EVIDENCE", + sourceCohortManifestSha256:hash, + sourceHorizonCounts:source, + originalPopulationCounts:{ + persistedNormalizedRows:count(pop.rows[0]?.population_rows??0), + distinctConfirmedOperatingLegIds: + count(pop.rows[0]?.distinct_source_confirmed_operating_leg_ids??0), + ambiguousOrMarketingRows:count(pop.rows[0]?.ambiguous_or_codeshared_rows??0) + }, + independentlyVerifiedPRE:pre, + prospectiveScheduleRevisionOutcomes:outcome, + reservedProjectRestUnits:used,projectRestUnitCeiling:ceiling, + actualProviderBillingIndependentReconciliationRequired:true, + webhookInOutUnresolvedIndependentReconciliationRequired:true, + originalContentRightsIndependentlyProvenByThisAudit:false, + actualDepartureOrRunwayTimeCertified:false, + missingObservationNotNegative:true, + providerCalls:0,databaseWrites:0,scientificGate5Passed:false, + phase5FreezeAuthorized:false,phase6Authorized:false + }; + await db.query("ROLLBACK");tx=false; + console.log(JSON.stringify(payload)); + }finally{ + if(tx)await db.query("ROLLBACK").catch(()=>undefined); + await db.end().catch(()=>undefined); + } +} +if(process.argv[1]?.endsWith("v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts")) + void main().catch(e=>{ + const msg=e instanceof Error?e.message:""; + console.error(JSON.stringify({ + status:"G5A_INDEPENDENT_NO_PROVIDER_AUDIT_HOLD", + reason:/^P4_G5_G5A_INDEPENDENT_[A-Z0-9_]+_HOLD$/.test(msg)? + msg:"G5A_INDEPENDENT_UNKNOWN_REDACTED_HOLD", + rawContentPrinted:false,providerCalls:0,databaseWrites:0, + scientificGate5Passed:false + })); + process.exitCode=2; + }); From 839b3873d030b2478d89a38f6e8769acbb9dbbdd Mon Sep 17 00:00:00 2001 From: Hamza Khan <139022998+HKcode22@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:27:12 -0800 Subject: [PATCH 2/5] Match actual V0076 owner schema: cohort ID is on budget not owner table --- ...9_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts b/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts index 795aafc72..88421600a 100644 --- a/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts +++ b/scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts @@ -75,7 +75,7 @@ export const G5A_SOURCE_AUDIT_SQL_V39=[ "AND b.manifest_sha256=o.manifest_sha256", "LEFT JOIN clean.fids_query_response s", "ON s.population_query_id=b.population_query_id", - "WHERE o.manifest_sha256=$1 AND o.cohort_id IS NULL", + "WHERE o.manifest_sha256=$1", "GROUP BY o.horizon ORDER BY o.horizon" ].join(" "); export const G5A_PRE_AUDIT_SQL_V39=[ From 0b171a1be4be543b558f204d64fcd252dcd5d683 Mon Sep 17 00:00:00 2001 From: Hamza Khan <139022998+HKcode22@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:27:40 -0800 Subject: [PATCH 3/5] GitHub-only independent G5A cohort read-only real audit after frozen T+2h watermark, no paid provider --- ...ase4-gate5-g5a-independent-final-audit.yml | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/phase4-gate5-g5a-independent-final-audit.yml diff --git a/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml b/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml new file mode 100644 index 000000000..105d2a7aa --- /dev/null +++ b/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml @@ -0,0 +1,75 @@ +name: Phase4 Gate5 G5A Independent Cohort Audit (No Provider) +on: + pull_request: + branches: [main] + paths: + - ".github/workflows/phase4-gate5-g5a-independent-final-audit.yml" + - "scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts" + - "tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts" + push: + branches: [main] + paths: + - ".github/workflows/phase4-gate5-g5a-independent-final-audit.yml" + - "scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts" + - "tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts" + workflow_dispatch: + schedule: + # Exact Nov 5, 2026 only (code also hard-fences this date range) + - cron: "12 5 5 11 *" +permissions: + contents: read +concurrency: + group: gate5-g5a-wsss-20261105-independent-readonly-audit + cancel-in-progress: false +jobs: + offline-audit-unit: + if: ${{ github.event_name == 'pull_request' || github.event_name == 'push' }} + runs-on: ubuntu-latest + timeout-minutes: 8 + env: + DATABASE_URL: "" + GATE05_AUTOMATION_DATABASE_URL: "" + V39_DATABASE_RUNTIME_URL: "" + P4_G5_SOURCE_OWNER_DATABASE_URL: "" + AERODATABOX_API_KEY: "" + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-node@v4 + with: + node-version: "20" + cache: npm + - run: npm ci --include=dev --no-audit --no-fund + - name: Offline 3-horizon, no-provider, no-write independent audit tests + run: | + set -Eeuo pipefail + npx vitest run tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts + echo 'PROVIDER_CALLS=0 DATABASE_WRITES=0' + audit-independent: + name: audit-independent + if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} + runs-on: ubuntu-latest + timeout-minutes: 9 + environment: phase2g-paid + env: + ADB_AUTO_COLLECT: "0" + V39_PHASE6_PROCESS_ARMED: "0" + GITHUB_EVENT_SCHEDULE: ${{ github.event.schedule }} + GATE05_AUTOMATION_DATABASE_URL: ${{ secrets.GATE05_AUTOMATION_DATABASE_URL }} + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - uses: actions/setup-node@v4 + with: + node-version: "20" + cache: npm + - run: npm ci --include=dev --no-audit --no-fund + - name: Independent original and PRE and post labels only (read-only) + run: | + set -Eeuo pipefail + set +x + test -z "${DATABASE_URL:-}${V39_DATABASE_RUNTIME_URL:-}${P4_G5_SOURCE_OWNER_DATABASE_URL:-}${AERODATABOX_API_KEY:-}${RAPIDAPI_KEY:-}" + test "$(git rev-parse HEAD)" = "${GITHUB_SHA}" + node --import tsx scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts From 6cc80dd89aa92984980ebba71bdb97bb4f1a7808 Mon Sep 17 00:00:00 2001 From: Hamza Khan <139022998+HKcode22@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:28:18 -0800 Subject: [PATCH 4/5] =?UTF-8?q?Tests:=20independent=20Gate5=20real=20audit?= =?UTF-8?q?=20date-only=20GitHub=20reader=20and=20source=E2=86=92V0077?= =?UTF-8?q?=E2=86=92PRE=E2=86=92POST=20counts=20without=20any=20provider/D?= =?UTF-8?q?B=20writes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...te5_g5a_independent_real_audit_v39.test.ts | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts diff --git a/tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts b/tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts new file mode 100644 index 000000000..e3c81bbc0 --- /dev/null +++ b/tests/phase4_gate5_g5a_independent_real_audit_v39.test.ts @@ -0,0 +1,88 @@ +import {describe,it,expect} from "vitest"; +import { + requireG5AIndependentAuditContextV39, + G5A_SOURCE_AUDIT_SQL_V39,G5A_PRE_AUDIT_SQL_V39, + G5A_POPULATION_AUDIT_SQL_V39,G5A_INDEPENDENT_AUDIT_SCHEMA_V39 +} from "../scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit"; +const main="a".repeat(40),event="2026-11-05T05:12:30.000Z"; +const env=()=>({ + GITHUB_ACTIONS:"true", + GITHUB_REPOSITORY:"HKcode22/ReplitTranvr", + GITHUB_REF:"refs/heads/main", + GITHUB_SHA:main,GITHUB_RUN_ATTEMPT:"1", + GITHUB_EVENT_NAME:"schedule", + GITHUB_EVENT_SCHEDULE:"12 5 5 11 *", + GITHUB_JOB:"audit-independent", + GITHUB_WORKFLOW:"Phase4 Gate5 G5A Independent Cohort Audit (No Provider)", + GITHUB_WORKFLOW_REF:"HKcode22/ReplitTranvr/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml@refs/heads/main", + GATE05_AUTOMATION_DATABASE_URL:"postgresql://audit:fixture@localhost/disposable", + ADB_AUTO_COLLECT:"0",V39_PHASE6_PROCESS_ARMED:"0" +}); +describe("G5A real independent no-provider cohort read-only auditor",()=>{ + it("admits only true main, correct date, audit role, schedule/manual",()=>{ + expect(()=>requireG5AIndependentAuditContextV39( + env(),main,Date.parse(event))).not.toThrow(); + expect(()=>requireG5AIndependentAuditContextV39({ + ...env(),GITHUB_EVENT_NAME:"workflow_dispatch",GITHUB_EVENT_SCHEDULE:"" + },main,Date.parse(event))).not.toThrow(); + }); + it("refuses source writer/paid key/admin URL and any fork/push/PR/replay",()=>{ + const errors=[ + {GITHUB_EVENT_NAME:"push"},{GITHUB_EVENT_NAME:"pull_request"}, + {GITHUB_REF:"refs/pull/375/merge"}, + {GITHUB_REPOSITORY:"another/fork"}, + {GITHUB_JOB:"not-independent"}, + {GITHUB_RUN_ATTEMPT:"2"}, + {GITHUB_SHA:"b".repeat(40)}, + {GITHUB_WORKFLOW:"another"}, + {GITHUB_WORKFLOW_REF:"another"}, + {GITHUB_EVENT_SCHEDULE:"0 0 * * *"}, + {GATE05_AUTOMATION_DATABASE_URL:""}, + {DATABASE_URL:"postgresql://admin:fixture@localhost/disposable"}, + {V39_DATABASE_RUNTIME_URL:"postgresql://app:fixture@localhost/disposable"}, + {P4_G5_SOURCE_OWNER_DATABASE_URL:"postgresql://writer:fixture@localhost/disposable"}, + {AERODATABOX_API_KEY:"fake-paid"}, + {ADB_AUTO_COLLECT:"1"}, + {V39_PHASE6_PROCESS_ARMED:"1"}, + ]; + for(const edit of errors)expect(()=>requireG5AIndependentAuditContextV39( + {...env(),...edit},main,Date.parse(event))) + .toThrow("P4_G5_G5A_INDEPENDENT_GITHUB_READER_DATE_OR_ISOLATION_HOLD"); + }); + it("refuses before physical T+2h and in another calendar year",()=>{ + for(const date of ["2026-11-04T23:50:00.000Z", + "2026-11-05T05:09:59.999Z", + "2027-11-05T05:12:00.000Z"]) + expect(()=>requireG5AIndependentAuditContextV39( + env(),main,Date.parse(date))) + .toThrow("P4_G5_G5A_INDEPENDENT_GITHUB_READER_DATE_OR_ISOLATION_HOLD"); + }); + it("source readback counts only actual V0076 committed physical reservations and exact V0077 original",()=>{ + expect(G5A_INDEPENDENT_AUDIT_SCHEMA_V39) + .toBe("v39.phase4.g5a-independent-real-source-pre-post-counts.v1"); + for(const s of ["phase4_g5_fids_physical_owner_v39", + "phase4_g5_fids_allowed_query_v39", + "phase4_g5_fids_physical_attempt_v39", + "phase4_g5_fids_original_binding_v39", + "fids_query_response","manifest_sha256=$1", + "q.prediction_cutoff_utc","original_response_sha256=s.response_hash" + ]) expect(G5A_SOURCE_AUDIT_SQL_V39).toContain(s); + expect(G5A_SOURCE_AUDIT_SQL_V39).not.toContain("o.cohort_id"); + expect(G5A_SOURCE_AUDIT_SQL_V39).not.toContain("raw_payload"); + }); + it("PRE audit compares actual created at/decision cutoff without backfilling",()=>{ + for(const s of ["flight_snapshots","frame_hash=$1", + "prediction_state","s.created_at<=s.prediction_cutoff_utc", + "s.created_at>s.prediction_cutoff_utc","fids_response_hash", + "selected_t_version"]) + expect(G5A_PRE_AUDIT_SQL_V39).toContain(s); + expect(G5A_PRE_AUDIT_SQL_V39).not.toContain("UPDATE "); + }); + it("member denominator only comes from independently bound originals",()=>{ + for(const s of ["flight_population", + "phase4_g5_fids_original_binding_v39", + "p.population_query_id","b.manifest_sha256=$1", + "confirmed_operating_leg","requested_airport_primary"]) + expect(G5A_POPULATION_AUDIT_SQL_V39).toContain(s); + }); +}); From 2b8935cd7f13baf0b2808f7ec40ee4844da79510 Mon Sep 17 00:00:00 2001 From: Hamza Khan <139022998+HKcode22@users.noreply.github.com> Date: Tue, 3 Nov 2026 06:31:27 -0800 Subject: [PATCH 5/5] Persist only anonymized independent real source/PRE/POST audit aggregates to Gate5 issue #293 for cross-chat checkpoint --- ...ase4-gate5-g5a-independent-final-audit.yml | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml b/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml index 105d2a7aa..9bcf3bf8a 100644 --- a/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml +++ b/.github/workflows/phase4-gate5-g5a-independent-final-audit.yml @@ -48,6 +48,9 @@ jobs: echo 'PROVIDER_CALLS=0 DATABASE_WRITES=0' audit-independent: name: audit-independent + permissions: + contents: read + issues: write if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} runs-on: ubuntu-latest timeout-minutes: 9 @@ -67,9 +70,37 @@ jobs: cache: npm - run: npm ci --include=dev --no-audit --no-fund - name: Independent original and PRE and post labels only (read-only) + env: + GH_TOKEN: ${{ github.token }} run: | set -Eeuo pipefail set +x test -z "${DATABASE_URL:-}${V39_DATABASE_RUNTIME_URL:-}${P4_G5_SOURCE_OWNER_DATABASE_URL:-}${AERODATABOX_API_KEY:-}${RAPIDAPI_KEY:-}" test "$(git rev-parse HEAD)" = "${GITHUB_SHA}" - node --import tsx scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts + node --import tsx scripts/v39_phase4_gate5_g5a_independent_real_cohort_readonly_audit.ts > "$RUNNER_TEMP/g5a-audit-stdout.json" + jq -ce ' + if .schema == "v39.phase4.g5a-independent-real-source-pre-post-counts.v1" + and .providerCalls == 0 and .databaseWrites == 0 + and .scientificGate5Passed == false + and (.sourceHorizonCounts | type == "array") + and (.independentlyVerifiedPRE | type == "array") + and (.prospectiveScheduleRevisionOutcomes | type == "array") + then {schema,status,sourceCohortManifestSha256,sourceHorizonCounts, + originalPopulationCounts,independentlyVerifiedPRE, + prospectiveScheduleRevisionOutcomes,reservedProjectRestUnits, + projectRestUnitCeiling,actualProviderBillingIndependentReconciliationRequired, + webhookInOutUnresolvedIndependentReconciliationRequired, + scientificGate5Passed,providerCalls,databaseWrites} + else error("G5A_UNREVIEWED_AUDIT_OUTPUT_HOLD") end + ' "$RUNNER_TEMP/g5a-audit-stdout.json" > "$RUNNER_TEMP/g5a-audit-safe.json" + { + printf '### Gate5 independent G5A real cohort counts (no provider)\n' + printf 'GitHub run: https://github.com/HKcode22/ReplitTranvr/actions/runs/%s\n' "$GITHUB_RUN_ID" + printf 'Reviewed main SHA: %s\n\n' "$GITHUB_SHA" + printf '~~~json\n' + cat "$RUNNER_TEMP/g5a-audit-safe.json" + printf '\n~~~\n' + printf '\nCounts are measurements, NOT an automatic scientific PASS.\n' + } > "$RUNNER_TEMP/g5a-safe-checkpoint.md" + cat "$RUNNER_TEMP/g5a-safe-checkpoint.md" >> "$GITHUB_STEP_SUMMARY" + gh issue comment 293 --repo HKcode22/ReplitTranvr --body-file "$RUNNER_TEMP/g5a-safe-checkpoint.md"