Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
test(hcc): handle rejected fixture commands once
Alfredo Lopezef854c1b9027
diff --git a/scripts/e2e/_lib/hcc-watch-api-proxy.mjs b/scripts/e2e/_lib/hcc-watch-api-proxy.mjsindex 270f7bdd5..31eca8cfb 100644--- a/scripts/e2e/_lib/hcc-watch-api-proxy.mjs+++ b/scripts/e2e/_lib/hcc-watch-api-proxy.mjs@@ -67,6 +67,7 @@ export function createProxy({const bookmarks = createBookmarkObservation()let pause = nulllet commandId = null+ let commandContent = nullconst writeRecord = (name, fields) => {fs.writeFileSync(`${controlDir}/${name}.next`, JSON.stringify(fields), { mode: 0o600 })fs.renameSync(`${controlDir}/${name}.next`, `${controlDir}/${name}.json`)@@ -160,14 +161,19 @@ export function createProxy({} else forward()})const poll = setInterval(() => {+ let observedId = nulltry {if (!fs.existsSync(`${controlDir}/command.json`)) return- const command = validateCommand(- JSON.parse(fs.readFileSync(`${controlDir}/command.json`, 'utf8')),- allowedPaths- )- if (command.id === commandId) return- commandId = command.id+ const content = fs.readFileSync(`${controlDir}/command.json`, 'utf8')+ if (content === commandContent) return+ // Remember rejected input too: one file publication produces one verdict.+ commandContent = content+ const candidate = JSON.parse(content)+ observedId = typeof candidate?.id === 'string' && /^[a-zA-Z0-9-]{1,80}$/.test(candidate.id)+ ? candidate.id : null+ if (observedId !== null && observedId === commandId) return+ if (observedId !== null) commandId = observedId+ const command = validateCommand(candidate, allowedPaths)if (command.action === 'arm') {if (pause) throw new Error('pause_already_active')pause = {@@ -201,7 +207,7 @@ export function createProxy({acknowledge({ id: command.id, state: 'cut', count })}} catch {- acknowledge({ id: commandId, state: 'rejected' })+ acknowledge({ id: observedId, state: 'rejected' })}}, 100)const churn = setInterval(() => {diff --git a/scripts/e2e/_lib/hcc-watch-bookmarks.mjs b/scripts/e2e/_lib/hcc-watch-bookmarks.mjsindex a4aa358a9..116e70ac2 100644--- a/scripts/e2e/_lib/hcc-watch-bookmarks.mjs+++ b/scripts/e2e/_lib/hcc-watch-bookmarks.mjs@@ -138,7 +138,7 @@ export function createBookmarkObservation({reasons: state.watchResponses ? [...state.reasons].sort() : ['no-watch-response'],receipt:state.observedBookmarks > 0 ? 'observed' : complete ? 'not-observed' : 'unknown',- disconnectBenefit: 'NO_DEMOSTRADO',+ disconnectBenefit: 'NOT_DEMONSTRATED',},]})diff --git a/scripts/e2e/_lib/hcc-watch-pr-a.sh b/scripts/e2e/_lib/hcc-watch-pr-a.shindex 22a3511c0..3a9b5cd95 100755--- a/scripts/e2e/_lib/hcc-watch-pr-a.sh+++ b/scripts/e2e/_lib/hcc-watch-pr-a.sh@@ -231,7 +231,7 @@ hcc_pr_a_run() {printf 'PR_A_PROTECTED_API_RECOVERY=PASS\n'hcc_pr_a_logs > "$NP604_EVIDENCE/pr-a-observations.jsonl"# Receipt is a separate finite observation, never an automatic D2-b gate.- hcc_pr_a_bookmark_report || printf 'PR_A_BOOKMARK_RECEIPT=NO_DEMOSTRADO (artifact unavailable)\n'+ hcc_pr_a_bookmark_report || printf 'PR_A_BOOKMARK_RECEIPT=NOT_DEMONSTRATED (artifact unavailable)\n'}hcc_pr_a_bookmark_pod_witness() {@@ -244,11 +244,11 @@ hcc_pr_a_bookmark_pod_witness() {}hcc_pr_a_bookmark_unknown() {- jq -n '{boundary:"verified-upstream-watch-response",window:null,receiptStatus:"NO_DEMOSTRADO",- disconnectBenefit:"NO_DEMOSTRADO",reason:"observation-or-identity-unavailable",+ jq -n '{boundary:"verified-upstream-watch-response",window:null,receiptStatus:"NOT_DEMONSTRATED",+ disconnectBenefit:"NOT_DEMONSTRATED",reason:"observation-or-identity-unavailable",byWatch:{McpServer:{bookmarks:null,coverage:"unknown"},Context:{bookmarks:null,coverage:"unknown"}}}' \> "$NP604_EVIDENCE/bookmark-receipt.json"- printf 'PR_A_BOOKMARK_RECEIPT=NO_DEMOSTRADO\n'+ printf 'PR_A_BOOKMARK_RECEIPT=NOT_DEMONSTRATED\n'}hcc_pr_a_bookmark_report() {@@ -281,8 +281,8 @@ hcc_pr_a_bookmark_report() {($hccAfter.startedAt|epoch)<=.value.firstWatchAtMs then .else .value.coverage="unknown" | .value.bookmarks=null | .value.receipt="unknown" |.value.reasons += ["identity-unknown"] end) |- .receiptStatus=(if any(.byWatch[]; .receipt=="observed") then "OBSERVED_UPSTREAM" else "NO_DEMOSTRADO" end) |- .disconnectBenefit="NO_DEMOSTRADO"' > "$NP604_EVIDENCE/bookmark-receipt.json" || {+ .receiptStatus=(if any(.byWatch[]; .receipt=="observed") then "OBSERVED_UPSTREAM" else "NOT_DEMONSTRATED" end) |+ .disconnectBenefit="NOT_DEMONSTRATED"' > "$NP604_EVIDENCE/bookmark-receipt.json" || {hcc_pr_a_bookmark_unknown; return;}jq -r '"PR_A_BOOKMARK_RECEIPT="+.receiptStatus+" (callback processing and benefit not demonstrated)"' \diff --git a/scripts/tests/hcc-watch-bookmarks.test.mjs b/scripts/tests/hcc-watch-bookmarks.test.mjsindex 85ad3513e..6d9251c8d 100644--- a/scripts/tests/hcc-watch-bookmarks.test.mjs+++ b/scripts/tests/hcc-watch-bookmarks.test.mjs@@ -32,7 +32,7 @@ test('counts only top-level BOOKMARK by watch across arbitrary UTF8/frame splitsassert.equal(result.byWatch.McpServer.bookmarks, 2)assert.equal(result.byWatch.Context.bookmarks, 0)assert.equal(result.byWatch.Context.receipt, 'not-observed')- assert.equal(result.byWatch.McpServer.disconnectBenefit, 'NO_DEMOSTRADO')+ assert.equal(result.byWatch.McpServer.disconnectBenefit, 'NOT_DEMONSTRATED')assert.equal(result.startedAtMs, 10)assert.equal(result.endedAtMs, 20)})@@ -237,10 +237,10 @@ hcc_pr_a_bookmark_reportconst report = JSON.parse(readFileSync(join(directory, 'bookmark-receipt.json')))assert.equal(report.receiptStatus,- image === 'fixture-image' ? 'OBSERVED_UPSTREAM' : 'NO_DEMOSTRADO'+ image === 'fixture-image' ? 'OBSERVED_UPSTREAM' : 'NOT_DEMONSTRATED')assert.equal(report.byWatch.McpServer.bookmarks, image === 'fixture-image' ? 1 : null)- assert.equal(report.disconnectBenefit, 'NO_DEMOSTRADO')+ assert.equal(report.disconnectBenefit, 'NOT_DEMONSTRATED')}writeFileSync(join(directory, 'observation.json'), 'unavailable')const run = spawnSync('/bin/bash', ['-c', script], {diff --git a/scripts/tests/hcc-watch-control.test.mjs b/scripts/tests/hcc-watch-control.test.mjsnew file mode 100644index 000000000..c6c686de3--- /dev/null+++ b/scripts/tests/hcc-watch-control.test.mjs@@ -0,0 +1,51 @@+import assert from 'node:assert/strict'+import fs from 'node:fs'+import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import test from 'node:test'+import { createProxy } from '../e2e/_lib/hcc-watch-api-proxy.mjs'+import { createFixtureTls } from '../e2e/_lib/hcc-watch-tls.mjs'++test('rejects malformed publications once and accepts the next valid command', t => {+ t.mock.timers.enable({ apis: ['setInterval'] })+ const controlDir = mkdtempSync(join(tmpdir(), 'hcc-rejected-command-'))+ const tls = createFixtureTls('127.0.0.1')+ const proxy = createProxy({ ...tls, upstreamCa: tls.cert,+ allowedPaths: [], controlDir, periodMs: 60000, minAgeMs: 60000 })+ const rename = fs.renameSync+ let acknowledgements = 0+ t.mock.method(fs, 'renameSync', (from, to) => {+ if (to === join(controlDir, 'ack.json')) acknowledgements += 1+ return rename(from, to)+ })+ const write = value => writeFileSync(join(controlDir, 'command.json'), value)+ const ack = () => JSON.parse(readFileSync(join(controlDir, 'ack.json'), 'utf8'))+ try {+ write(JSON.stringify({ id: 'invalid-action', action: 'unknown' }))+ t.mock.timers.tick(100)+ assert.deepEqual(ack(), { id: 'invalid-action', state: 'rejected' })+ t.mock.timers.tick(1000)+ assert.equal(acknowledgements, 1)+ write('{')+ t.mock.timers.tick(100)+ assert.deepEqual(ack(), { id: null, state: 'rejected' })+ t.mock.timers.tick(1000)+ assert.equal(acknowledgements, 2)+ write(JSON.stringify({ id: { untrusted: 'value' }, action: 'cut', kind: 'both' }))+ t.mock.timers.tick(100)+ assert.deepEqual(ack(), { id: null, state: 'rejected' })+ t.mock.timers.tick(1000)+ assert.equal(acknowledgements, 3)+ write(JSON.stringify({ id: 'valid-next', action: 'observe-bookmarks' }))+ t.mock.timers.tick(100)+ assert.deepEqual(ack(), { id: 'valid-next', state: 'observed' })+ assert.equal(acknowledgements, 4)+ write(JSON.stringify({ id: 'valid-next', action: 'unknown' }))+ t.mock.timers.tick(100)+ assert.equal(acknowledgements, 4, 'processed IDs remain idempotent')+ } finally {+ proxy.close()+ rmSync(controlDir, { recursive: true, force: true })+ }+})diff --git a/scripts/tests/test-hcc-watch-api-proxy.sh b/scripts/tests/test-hcc-watch-api-proxy.shindex cb357a366..c72060499 100755--- a/scripts/tests/test-hcc-watch-api-proxy.sh+++ b/scripts/tests/test-hcc-watch-api-proxy.sh@@ -5,4 +5,4 @@ command -v openssl >/dev/null || { echo 'FAIL: openssl is required' >&2; exit 1;node -e 'if (Number(process.versions.node.split(".")[0]) !== 24) { console.error("FAIL: Node 24 is required"); process.exit(1) }'# Test certificates and the generator output stay in Node memory; never tee or# redirect the generator itself to any artifact. The reporter prints test results.-exec node --test --test-timeout=15000 "$SCRIPT_DIR/hcc-watch-api-proxy.test.mjs" "$SCRIPT_DIR/hcc-watch-bookmarks.test.mjs" "$SCRIPT_DIR/hcc-watch-tls.test.mjs" "$SCRIPT_DIR/hcc-watch-config.test.mjs"+exec node --test --test-timeout=15000 "$SCRIPT_DIR/hcc-watch-api-proxy.test.mjs" "$SCRIPT_DIR/hcc-watch-bookmarks.test.mjs" "$SCRIPT_DIR/hcc-watch-tls.test.mjs" "$SCRIPT_DIR/hcc-watch-config.test.mjs" "$SCRIPT_DIR/hcc-watch-control.test.mjs"