Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(hcc): record bounded upstream bookmark observations

Alfredo Lopezfcb28b3dc046
diff --git a/scripts/e2e/_lib/hcc-watch-api-proxy.mjs b/scripts/e2e/_lib/hcc-watch-api-proxy.mjs
index 162e37bd1..343d8d9c0 100644
--- a/scripts/e2e/_lib/hcc-watch-api-proxy.mjs
+++ b/scripts/e2e/_lib/hcc-watch-api-proxy.mjs
@@ -2,6 +2,7 @@
import fs from 'node:fs'
import https from 'node:https'
import { pathToFileURL } from 'node:url'
+import { createBookmarkObservation } from './hcc-watch-bookmarks.mjs'
export function validateCommand(command, allowedPaths) {
if (!command || typeof command.id !== 'string' || !/^[a-zA-Z0-9-]{1,80}$/.test(command.id))
@@ -22,7 +23,7 @@ export function validateCommand(command, allowedPaths) {
} else if (command.action === 'release') {
if (typeof command.pauseId !== 'string' || !/^[a-zA-Z0-9-]{1,80}$/.test(command.pauseId))
throw new Error('invalid_pause_id')
- } else throw new Error('invalid_control_action')
+ } else if (command.action !== 'observe-bookmarks') throw new Error('invalid_control_action')
return command
}
@@ -38,6 +39,7 @@ export function createProxy({
minAgeMs,
}) {
const streams = new Set()
+ const bookmarks = createBookmarkObservation()
let pause = null
let commandId = null
const writeRecord = (name, fields) => {
@@ -101,6 +103,12 @@ export function createProxy({
},
incoming => {
response.writeHead(incoming.statusCode, incoming.headers)
+ if (watch && request.method === 'GET') {
+ const observer = bookmarks.open(kind, incoming.headers, incoming.statusCode)
+ incoming.on('data', chunk => observer.write(chunk))
+ incoming.once('end', () => observer.end())
+ incoming.once('close', () => observer.close())
+ }
incoming.pipe(response)
}
)
@@ -143,6 +151,9 @@ export function createProxy({
throw new Error('pause_not_held')
finishPause('released')
acknowledge({ id: command.id, state: 'released' })
+ } else if (command.action === 'observe-bookmarks') {
+ writeRecord('bookmarks', bookmarks.finish())
+ acknowledge({ id: command.id, state: 'observed' })
} else {
let count = 0
for (const stream of streams) {
diff --git a/scripts/e2e/_lib/hcc-watch-bookmarks.mjs b/scripts/e2e/_lib/hcc-watch-bookmarks.mjs
new file mode 100644
index 000000000..a4aa358a9
--- /dev/null
+++ b/scripts/e2e/_lib/hcc-watch-bookmarks.mjs
@@ -0,0 +1,149 @@
+// Development-only observation of verified upstream watch bytes, never bodies
+// in an artifact. Forwarding remains the proxy's independent streaming pipe.
+export function createBookmarkObservation({
+ maxFrameBytes = 65536,
+ maxStreams = 32,
+ now = Date.now,
+} = {}) {
+ if (
+ !Number.isInteger(maxFrameBytes) ||
+ maxFrameBytes < 64 ||
+ maxFrameBytes > 65536 ||
+ !Number.isInteger(maxStreams) ||
+ maxStreams < 1 ||
+ maxStreams > 32
+ )
+ throw new Error('invalid-observation-bounds')
+ const startedAtMs = now()
+ const active = new Set()
+ let endedAtMs = null
+ const kinds = Object.fromEntries(
+ ['McpServer', 'Context'].map(kind => [
+ kind,
+ {
+ watchResponses: 0,
+ observedBookmarks: 0,
+ firstWatchAtMs: null,
+ reasons: new Set(),
+ },
+ ])
+ )
+ const noop = { write() {}, end() {}, close() {} }
+ const unknown = (state, reason) => state.reasons.add(reason)
+ function open(kind, headers, statusCode) {
+ if (endedAtMs !== null || !kinds[kind]) return noop
+ const state = kinds[kind]
+ state.watchResponses++
+ state.firstWatchAtMs ??= now()
+ if (
+ statusCode !== 200 ||
+ !/^application\/json(?:;|$)/i.test(headers['content-type'] ?? '') ||
+ (headers['content-encoding'] && headers['content-encoding'] !== 'identity')
+ ) {
+ unknown(state, 'unsupported-response')
+ return noop
+ }
+ if (active.size >= maxStreams) {
+ unknown(state, 'observer-limit')
+ return noop
+ }
+ let pending = Buffer.alloc(0)
+ let oversized = false
+ let closed = false
+ const decoder = new TextDecoder('utf-8', { fatal: true })
+ const frame = bytes => {
+ try {
+ const text = decoder.decode(bytes).trim()
+ if (!text) return
+ const event = JSON.parse(text)
+ if (
+ !['ADDED', 'MODIFIED', 'DELETED', 'ERROR', 'BOOKMARK'].includes(event?.type) ||
+ !event.object ||
+ typeof event.object !== 'object'
+ )
+ throw new Error('invalid-frame')
+ if (event.type === 'BOOKMARK') {
+ if (
+ typeof event.object.metadata?.resourceVersion !== 'string' ||
+ !event.object.metadata.resourceVersion
+ ) {
+ throw new Error('invalid-bookmark')
+ }
+ state.observedBookmarks++
+ }
+ } catch {
+ unknown(state, 'malformed-frame')
+ }
+ }
+ const observer = {
+ write(chunk) {
+ if (closed || endedAtMs !== null) return
+ let offset = 0
+ while (offset < chunk.length) {
+ const newline = chunk.indexOf(10, offset)
+ const end = newline < 0 ? chunk.length : newline
+ if (!oversized) {
+ if (pending.length + end - offset > maxFrameBytes) {
+ unknown(state, 'oversized-frame')
+ pending = Buffer.alloc(0)
+ oversized = true
+ } else pending = Buffer.concat([pending, chunk.subarray(offset, end)])
+ }
+ if (newline < 0) break
+ if (!oversized) frame(pending)
+ pending = Buffer.alloc(0)
+ oversized = false
+ offset = newline + 1
+ }
+ },
+ end() {
+ if (closed) return
+ if (pending.length && !oversized) frame(pending)
+ pending = Buffer.alloc(0)
+ closed = true
+ active.delete(observer)
+ },
+ close() {
+ if (closed) return
+ if (pending.length || oversized) unknown(state, 'partial-frame')
+ pending = Buffer.alloc(0)
+ closed = true
+ active.delete(observer)
+ },
+ }
+ active.add(observer)
+ return observer
+ }
+ function finish() {
+ if (endedAtMs === null) {
+ endedAtMs = now()
+ for (const observer of active) observer.close()
+ }
+ return {
+ boundary: 'verified-upstream-watch-response',
+ startedAtMs,
+ endedAtMs,
+ limits: { maxFrameBytes, maxStreams },
+ byWatch: Object.fromEntries(
+ Object.entries(kinds).map(([kind, state]) => {
+ const complete = state.watchResponses > 0 && state.reasons.size === 0
+ return [
+ kind,
+ {
+ watchResponses: state.watchResponses,
+ firstWatchAtMs: state.firstWatchAtMs,
+ observedBookmarks: state.observedBookmarks,
+ bookmarks: complete ? state.observedBookmarks : null,
+ coverage: complete ? 'complete' : 'unknown',
+ reasons: state.watchResponses ? [...state.reasons].sort() : ['no-watch-response'],
+ receipt:
+ state.observedBookmarks > 0 ? 'observed' : complete ? 'not-observed' : 'unknown',
+ disconnectBenefit: 'NO_DEMOSTRADO',
+ },
+ ]
+ })
+ ),
+ }
+ }
+ return { open, finish }
+}
diff --git a/scripts/e2e/_lib/hcc-watch-pr-a.sh b/scripts/e2e/_lib/hcc-watch-pr-a.sh
index bcb0736a1..42d4ca858 100644
--- a/scripts/e2e/_lib/hcc-watch-pr-a.sh
+++ b/scripts/e2e/_lib/hcc-watch-pr-a.sh
@@ -152,6 +152,63 @@ hcc_pr_a_run() {
[ "$(np604_snapshot "$NP604_CONTROL")" = "$control_policy" ] || die 'PR A control policies changed'
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_pod_witness() {
+ kctl get pod "$1" -n "$HCC_NS" -o json | jq -ce --arg container "$2" '
+ . as $pod | [.status.containerStatuses[]? | select(.name==$container)][0] as $status |
+ {uid:.metadata.uid,name:.metadata.name,
+ image:([.spec.containers[] | select(.name==$container)][0].image),
+ imageID:$status.imageID,restarts:$status.restartCount,startedAt:$status.state.running.startedAt} |
+ select(.uid!=null and .image!=null and .imageID!=null and .restarts!=null and .startedAt!=null)'
+}
+
+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",
+ byWatch:{McpServer:{bookmarks:null,coverage:"unknown"},Context:{bookmarks:null,coverage:"unknown"}}}' \
+ > "$NP604_EVIDENCE/bookmark-receipt.json"
+ printf 'PR_A_BOOKMARK_RECEIPT=NO_DEMOSTRADO\n'
+}
+
+hcc_pr_a_bookmark_report() {
+ local proxy_pod hcc_pod proxy_before proxy_after hcc_before hcc_after observed
+ proxy_pod="$(hcc_pr_a_proxy_pod)" && hcc_pod="$(running_hcc_pod)" &&
+ proxy_before="$(hcc_pr_a_bookmark_pod_witness "$proxy_pod" proxy)" &&
+ hcc_before="$(hcc_pr_a_bookmark_pod_witness "$hcc_pod" host-context-controller)" || {
+ hcc_pr_a_bookmark_unknown; return;
+ }
+ hcc_pr_a_command observe-bookmarks &&
+ wait_until 5 'finite upstream bookmark observation' hcc_pr_a_ack observed &&
+ observed="$(kctl exec "pod/$proxy_pod" -n "$HCC_NS" -c proxy -- node -e \
+ 'process.stdout.write(require("fs").readFileSync("/churn-ctl/bookmarks.json"))')" &&
+ proxy_after="$(hcc_pr_a_bookmark_pod_witness "$proxy_pod" proxy)" &&
+ hcc_after="$(hcc_pr_a_bookmark_pod_witness "$hcc_pod" host-context-controller)" || {
+ hcc_pr_a_bookmark_unknown; return;
+ }
+ jq -n --arg image "$HCC_IMAGE" --argjson observation "$observed" \
+ --argjson hccBefore "$hcc_before" --argjson hccAfter "$hcc_after" \
+ --argjson proxyBefore "$proxy_before" --argjson proxyAfter "$proxy_after" '
+ def epoch: sub("\\.[0-9]+Z$";"Z") | fromdateiso8601 * 1000;
+ ($hccBefore==$hccAfter and $proxyBefore==$proxyAfter and
+ $hccAfter.image==$image and $proxyAfter.image==$image and
+ $hccAfter.imageID==$proxyAfter.imageID and
+ ($proxyAfter.startedAt|epoch)<=$observation.startedAtMs) as $sameIdentity |
+ $observation | .window={startedAtMs:.startedAtMs,endedAtMs:.endedAtMs} |
+ .configuredImage=$image | .hcc=$hccAfter | .proxy=$proxyAfter |
+ .byWatch |= with_entries(
+ if $sameIdentity and .value.firstWatchAtMs!=null and
+ ($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" || {
+ hcc_pr_a_bookmark_unknown; return;
+ }
+ jq -r '"PR_A_BOOKMARK_RECEIPT="+.receiptStatus+" (callback processing and benefit not demonstrated)"' \
+ "$NP604_EVIDENCE/bookmark-receipt.json"
}
hcc_pr_a_service_absent() {
diff --git a/scripts/e2e/_lib/hcc-watch-tls-manifest.mjs b/scripts/e2e/_lib/hcc-watch-tls-manifest.mjs
index 8af6cda67..c677f1571 100644
--- a/scripts/e2e/_lib/hcc-watch-tls-manifest.mjs
+++ b/scripts/e2e/_lib/hcc-watch-tls-manifest.mjs
@@ -3,6 +3,7 @@
import { spawnSync } from 'node:child_process'
import { generateKeyPairSync } from 'node:crypto'
import { readFileSync } from 'node:fs'
+import { dirname, join } from 'node:path'
const [name, namespace, run, proxySource] = process.argv.slice(2)
for (const value of [name, namespace, run])
@@ -87,6 +88,10 @@ process.stdout.write(
data: {
'config.json': JSON.stringify(config),
'proxy.mjs': readFileSync(proxySource, 'utf8'),
+ 'hcc-watch-bookmarks.mjs': readFileSync(
+ join(dirname(proxySource), 'hcc-watch-bookmarks.mjs'),
+ 'utf8'
+ ),
},
},
],
diff --git a/scripts/tests/hcc-watch-bookmarks.test.mjs b/scripts/tests/hcc-watch-bookmarks.test.mjs
new file mode 100644
index 000000000..f2ccdecbb
--- /dev/null
+++ b/scripts/tests/hcc-watch-bookmarks.test.mjs
@@ -0,0 +1,285 @@
+import assert from 'node:assert/strict'
+import { spawnSync } from 'node:child_process'
+import { generateKeyPairSync } from 'node:crypto'
+import { once } from 'node:events'
+import { mkdtempSync, readFileSync, rmSync, watch, writeFileSync } from 'node:fs'
+import https from 'node:https'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+import { PassThrough } from 'node:stream'
+import test from 'node:test'
+import { fileURLToPath } from 'node:url'
+import { createProxy } from '../e2e/_lib/hcc-watch-api-proxy.mjs'
+import { createBookmarkObservation } from '../e2e/_lib/hcc-watch-bookmarks.mjs'
+
+const headers = { 'content-type': 'application/json;stream=watch' }
+const bookmark = Buffer.from(
+ '{"type":"BOOKMARK","object":{"metadata":{"resourceVersion":"123"}}}\n'
+)
+const added = Buffer.from('{"type":"ADDED","object":{"spec":{"type":"BOOKMARK","text":"ñ"}}}\n')
+
+test('counts only top-level BOOKMARK by watch across arbitrary UTF8/frame splits', () => {
+ let clock = 10
+ const observation = createBookmarkObservation({ now: () => clock })
+ const mcp = observation.open('McpServer', headers, 200)
+ const context = observation.open('Context', headers, 200)
+ for (const byte of Buffer.concat([added, bookmark, bookmark])) mcp.write(Buffer.from([byte]))
+ context.write(added)
+ mcp.end()
+ context.end()
+ clock = 20
+ const result = observation.finish()
+ assert.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.startedAtMs, 10)
+ assert.equal(result.endedAtMs, 20)
+})
+
+test('unknown is not zero for absent, malformed, oversized, unsupported or partial observation', () => {
+ for (const variant of [
+ 'absent',
+ 'malformed',
+ 'oversized',
+ 'compressed',
+ 'partial',
+ 'invalid-utf8',
+ 'invalid-bookmark',
+ ]) {
+ const observation = createBookmarkObservation({ maxFrameBytes: 128 })
+ if (variant !== 'absent') {
+ const stream = observation.open(
+ 'McpServer',
+ variant === 'compressed' ? { ...headers, 'content-encoding': 'gzip' } : headers,
+ 200
+ )
+ if (variant === 'malformed') stream.write(Buffer.from('not-json\n'))
+ if (variant === 'oversized') stream.write(Buffer.from('x'.repeat(100000) + '\n'))
+ if (variant === 'partial') stream.write(bookmark.subarray(0, 10))
+ if (variant === 'invalid-utf8') stream.write(Buffer.from([255, 10]))
+ if (variant === 'invalid-bookmark')
+ stream.write(Buffer.from('{"type":"BOOKMARK","object":{}}\n'))
+ stream.close()
+ }
+ const result = observation.finish().byWatch.McpServer
+ assert.equal(result.bookmarks, null, variant)
+ assert.equal(result.coverage, 'unknown', variant)
+ assert.equal(result.receipt, 'unknown', variant)
+ }
+})
+
+test('positive receipt remains a lower bound after an oversized frame', () => {
+ const observation = createBookmarkObservation({ maxFrameBytes: 128 })
+ const stream = observation.open('McpServer', headers, 200)
+ stream.write(Buffer.concat([Buffer.from('x'.repeat(100000) + '\n'), bookmark]))
+ stream.end()
+ const result = observation.finish().byWatch.McpServer
+ assert.equal(result.bookmarks, null)
+ assert.equal(result.observedBookmarks, 1)
+ assert.equal(result.receipt, 'observed')
+ assert.deepEqual(result.reasons, ['oversized-frame'])
+})
+
+test('bounds active parser memory and freezes the finite observation window', () => {
+ let clock = 10
+ const observation = createBookmarkObservation({ maxStreams: 1, now: () => clock })
+ const stream = observation.open('McpServer', headers, 200)
+ observation.open('Context', headers, 200).write(bookmark)
+ stream.write(bookmark)
+ clock = 20
+ const first = observation.finish()
+ clock = 30
+ stream.write(bookmark)
+ observation.open('McpServer', headers, 200).write(bookmark)
+ assert.deepEqual(observation.finish(), first)
+ assert.deepEqual(first.byWatch.Context.reasons, ['observer-limit'])
+ assert.throws(() => createBookmarkObservation({ maxFrameBytes: 100000000 }))
+ assert.throws(() => createBookmarkObservation({ maxStreams: 10000 }))
+})
+
+test('observation preserves streamed bytes including malformed frames and backpressure', async () => {
+ const observation = createBookmarkObservation()
+ const observer = observation.open('McpServer', headers, 200)
+ const upstream = new PassThrough({ highWaterMark: 8 })
+ const downstream = new PassThrough({ highWaterMark: 8 })
+ const chunks = []
+ upstream.on('data', chunk => observer.write(chunk))
+ upstream.once('end', () => observer.end())
+ upstream.once('close', () => observer.close())
+ upstream.pipe(downstream)
+ downstream.on('data', chunk => chunks.push(chunk))
+ const ended = new Promise(resolve => downstream.once('end', resolve))
+ const input = Buffer.concat([added, Buffer.from('malformed\n'), bookmark])
+ for (const byte of input) upstream.write(Buffer.from([byte]))
+ upstream.end()
+ await ended
+ assert.deepEqual(Buffer.concat(chunks), input)
+ const result = observation.finish().byWatch.McpServer
+ assert.equal(result.observedBookmarks, 1)
+ assert.equal(result.bookmarks, null)
+})
+
+test('proxy observes the actual verified HTTPS response and publishes only a bounded summary', async () => {
+ const { privateKey } = generateKeyPairSync('rsa', {
+ modulusLength: 2048,
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
+ })
+ const generated = spawnSync(
+ 'openssl',
+ [
+ 'req',
+ '-new',
+ '-x509',
+ '-key',
+ '/dev/stdin',
+ '-days',
+ '1',
+ '-subj',
+ '/CN=localhost',
+ '-addext',
+ 'subjectAltName=DNS:localhost,IP:127.0.0.1',
+ '-addext',
+ 'basicConstraints=critical,CA:TRUE',
+ ],
+ { input: privateKey, encoding: 'utf8', timeout: 15000 }
+ )
+ assert.equal(generated.status, 0, 'in-memory TLS fixture generation')
+ const credentials = { key: privateKey, cert: generated.stdout }
+ const controlDir = mkdtempSync(join(tmpdir(), 'hcc-bookmark-observation-'))
+ const upstream = https.createServer(credentials, (_request, response) => {
+ response.writeHead(200, headers)
+ response.end(bookmark)
+ })
+ let proxy
+ try {
+ upstream.listen(0, '127.0.0.1')
+ await once(upstream, 'listening')
+ proxy = createProxy({
+ ...credentials,
+ upstreamCa: credentials.cert,
+ upstreamHost: '127.0.0.1',
+ upstreamPort: upstream.address().port,
+ allowedPaths: [],
+ controlDir,
+ periodMs: 60000,
+ minAgeMs: 60000,
+ })
+ proxy.server.listen(0, '127.0.0.1')
+ await once(proxy.server, 'listening')
+ const bytes = await new Promise((resolve, reject) => {
+ https
+ .get(
+ {
+ hostname: '127.0.0.1',
+ port: proxy.server.address().port,
+ path: '/apis/clerum.io/v1alpha1/namespaces/mcp-server/mcpservers?watch=true',
+ ca: credentials.cert,
+ signal: AbortSignal.timeout(3000),
+ },
+ response => {
+ const chunks = []
+ response.on('data', chunk => chunks.push(chunk))
+ response.once('end', () => resolve(Buffer.concat(chunks)))
+ response.once('error', reject)
+ }
+ )
+ .once('error', reject)
+ })
+ assert.deepEqual(bytes, bookmark)
+ await new Promise((resolve, reject) => {
+ const observer = watch(controlDir, () => {
+ try {
+ const ack = JSON.parse(readFileSync(join(controlDir, 'ack.json')))
+ if (ack.id !== 'receipt-window' || ack.state !== 'observed') return
+ clearTimeout(timeout)
+ observer.close()
+ resolve()
+ } catch {}
+ })
+ const timeout = setTimeout(() => {
+ observer.close()
+ reject(new Error('observation acknowledgement timeout'))
+ }, 3000)
+ writeFileSync(
+ join(controlDir, 'command.json'),
+ JSON.stringify({ id: 'receipt-window', action: 'observe-bookmarks' })
+ )
+ })
+ const report = JSON.parse(readFileSync(join(controlDir, 'bookmarks.json')))
+ assert.equal(report.byWatch.McpServer.bookmarks, 1)
+ assert.equal(report.byWatch.Context.bookmarks, null)
+ assert.equal(report.byWatch.Context.receipt, 'unknown')
+ assert.equal(JSON.stringify(report).includes('resourceVersion'), false)
+ } finally {
+ proxy?.close()
+ upstream.closeAllConnections()
+ upstream.close()
+ rmSync(controlDir, { recursive: true, force: true })
+ }
+})
+
+test('harness binds receipt to image and pod witnesses without turning zero or unknown into a D2-b failure', () => {
+ const directory = mkdtempSync(join(tmpdir(), 'hcc-bookmark-report-'))
+ const helper = fileURLToPath(new URL('../e2e/_lib/hcc-watch-pr-a.sh', import.meta.url))
+ const observation = createBookmarkObservation({ now: () => 1000 })
+ const stream = observation.open('McpServer', headers, 200)
+ stream.write(bookmark)
+ stream.end()
+ writeFileSync(join(directory, 'observation.json'), JSON.stringify(observation.finish()))
+ const script = `set -euo pipefail
+source "$HELPER"
+NP604_EVIDENCE="$REPORT_DIR" HCC_NS=fixture HCC_IMAGE=fixture-image
+hcc_pr_a_proxy_pod() { printf proxy; }
+running_hcc_pod() { printf hcc; }
+hcc_pr_a_bookmark_pod_witness() { printf '%s' "$WITNESS"; }
+hcc_pr_a_command() { :; }
+wait_until() { :; }
+kctl() { cat "$REPORT_DIR/observation.json"; }
+hcc_pr_a_bookmark_report
+`
+ try {
+ for (const image of ['fixture-image', 'other-image']) {
+ const witness = {
+ uid: 'fixture-pod',
+ image,
+ imageID: 'sha256:fixture',
+ restarts: 0,
+ startedAt: '1970-01-01T00:00:00Z',
+ }
+ const run = spawnSync('/bin/bash', ['-c', script], {
+ encoding: 'utf8',
+ timeout: 5000,
+ env: {
+ ...process.env,
+ HELPER: helper,
+ REPORT_DIR: directory,
+ WITNESS: JSON.stringify(witness),
+ },
+ })
+ assert.equal(run.status, 0, 'receipt observation never becomes a D2-b failure')
+ const report = JSON.parse(readFileSync(join(directory, 'bookmark-receipt.json')))
+ assert.equal(
+ report.receiptStatus,
+ image === 'fixture-image' ? 'OBSERVED_UPSTREAM' : 'NO_DEMOSTRADO'
+ )
+ assert.equal(report.byWatch.McpServer.bookmarks, image === 'fixture-image' ? 1 : null)
+ assert.equal(report.disconnectBenefit, 'NO_DEMOSTRADO')
+ }
+ writeFileSync(join(directory, 'observation.json'), 'unavailable')
+ const run = spawnSync('/bin/bash', ['-c', script], {
+ encoding: 'utf8',
+ timeout: 5000,
+ env: { ...process.env, HELPER: helper, REPORT_DIR: directory, WITNESS: '{}' },
+ })
+ assert.equal(run.status, 0)
+ assert.equal(
+ JSON.parse(readFileSync(join(directory, 'bookmark-receipt.json'))).byWatch.McpServer
+ .bookmarks,
+ null
+ )
+ } finally {
+ rmSync(directory, { recursive: true, force: true })
+ }
+})
diff --git a/scripts/tests/test-hcc-watch-api-proxy.sh b/scripts/tests/test-hcc-watch-api-proxy.sh
index 4fea92878..1d667f3f2 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"
+exec node --test --test-timeout=15000 "$SCRIPT_DIR/hcc-watch-api-proxy.test.mjs" "$SCRIPT_DIR/hcc-watch-bookmarks.test.mjs"