mirror of
https://github.com/stablyai/orca.git
synced 2026-09-23 08:02:31 +00:00
The enable workflow reads the director's `[orca-relay] regional rehome inventory` line out of Cloud Logging and pins the whole line with one regex. Adding `hostNotArrivedLast24Hours` in #21813 made every healthy line stop matching, so "Read fresh aggregate completion and abort evidence" threw "no aggregate regional rehome inventory evidence" and the fail-closed step disabled the durable switch at control generation 26. The parser now requires the six original fields and tolerates further ones in any order. Extra fields stay fenced by value shape rather than by pinning the whole line: a field must be a bare name and a non-negative integer or `none`, so `hostId=someone` is still not a counter and cannot ride along. An absent count reads as null, not zero, because an older director not reporting leaks is not the same as reporting none. `hostNotArrivedLast24Hours` and `oldestActiveAgeMs` now reach the evidence JSON and the operator step summary. Two guards close the chain, each verified to fail on the regression it exists for: a census in the relay package feeds the real formatter's output to the real parser, and a script-side test pins the parser's output to the fields the workflow summary renders. Claude-Session: https://claude.ai/session/ced32ebb-7155-4413-adad-1eccd14c2010
136 lines
5.6 KiB
JavaScript
136 lines
5.6 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { test } from 'node:test'
|
|
import { parseRegionalRehomeInventory } from './relay-rehome-aggregate-evidence.mjs'
|
|
import { readRelayWorkflow } from './relay-repository.mjs'
|
|
|
|
const now = Date.parse('2026-08-14T12:00:00Z')
|
|
|
|
test('selects the newest fresh aggregate-only regional rehome inventory', () => {
|
|
const result = parseRegionalRehomeInventory([
|
|
{
|
|
timestamp: '2026-08-14T11:58:00Z',
|
|
textPayload: '[orca-relay] regional rehome inventory active=2 awaitingReceipt=1 targetRegistered=1 completedLast24Hours=9 abortedLast24Hours=0 oldestActiveAgeMs=30000'
|
|
},
|
|
{
|
|
timestamp: '2026-08-14T11:50:00Z',
|
|
textPayload: '[orca-relay] regional rehome inventory active=1 awaitingReceipt=0 targetRegistered=1 completedLast24Hours=8 abortedLast24Hours=0 oldestActiveAgeMs=none'
|
|
}
|
|
], { now, maxAgeMs: 5 * 60_000 })
|
|
assert.deepEqual(result, {
|
|
timestamp: Date.parse('2026-08-14T11:58:00Z'),
|
|
active: 2,
|
|
awaitingReceipt: 1,
|
|
targetRegistered: 1,
|
|
completedLast24Hours: 9,
|
|
abortedLast24Hours: 0,
|
|
hostNotArrivedLast24Hours: null,
|
|
oldestActiveAgeMs: 30_000
|
|
})
|
|
})
|
|
|
|
test('reads a line the director grew a field on, wherever the field sits', () => {
|
|
const result = parseRegionalRehomeInventory([{
|
|
timestamp: '2026-08-14T11:58:00Z',
|
|
textPayload:
|
|
'[orca-relay] regional rehome inventory hostNotArrivedLast24Hours=4 active=2' +
|
|
' awaitingReceipt=1 targetRegistered=1 completedLast24Hours=9 abortedLast24Hours=7' +
|
|
' oldestActiveAgeMs=30000 someFieldFromALaterRelease=11'
|
|
}], { now, maxAgeMs: 5 * 60_000 })
|
|
assert.equal(result.hostNotArrivedLast24Hours, 4)
|
|
assert.equal(result.abortedLast24Hours, 7)
|
|
assert.equal(result.oldestActiveAgeMs, 30_000)
|
|
})
|
|
|
|
test('reports an unmeasured host-not-arrived count as absent, not as zero', () => {
|
|
const [withField, withoutField] = ['4', null].map((value) =>
|
|
parseRegionalRehomeInventory([{
|
|
timestamp: '2026-08-14T11:58:00Z',
|
|
textPayload:
|
|
'[orca-relay] regional rehome inventory active=0 awaitingReceipt=0 targetRegistered=0' +
|
|
' completedLast24Hours=0 abortedLast24Hours=0 oldestActiveAgeMs=none' +
|
|
(value === null ? '' : ` hostNotArrivedLast24Hours=${value}`)
|
|
}], { now, maxAgeMs: 5 * 60_000 })
|
|
)
|
|
assert.equal(withField.hostNotArrivedLast24Hours, 4)
|
|
assert.equal(withoutField.hostNotArrivedLast24Hours, null)
|
|
})
|
|
|
|
test('rejects stale, malformed, and identity-bearing lookalikes', () => {
|
|
assert.throws(() => parseRegionalRehomeInventory([{
|
|
timestamp: '2026-08-14T11:00:00Z',
|
|
textPayload: '[orca-relay] regional rehome inventory active=0 awaitingReceipt=0 targetRegistered=0 completedLast24Hours=0 abortedLast24Hours=0 oldestActiveAgeMs=none'
|
|
}], { now, maxAgeMs: 5 * 60_000 }), /stale/)
|
|
assert.throws(() => parseRegionalRehomeInventory([{
|
|
timestamp: '2026-08-14T11:59:00Z',
|
|
textPayload: '[orca-relay] regional rehome inventory active=0 hostId=secret'
|
|
}], { now }), /no aggregate/)
|
|
})
|
|
|
|
test('keeps out an identity-bearing field riding along on a complete line', () => {
|
|
const complete =
|
|
'[orca-relay] regional rehome inventory active=0 awaitingReceipt=0 targetRegistered=0' +
|
|
' completedLast24Hours=0 abortedLast24Hours=0 oldestActiveAgeMs=none'
|
|
for (const extra of [' hostId=secret', ' userId=someone@example.test', ' note=a b']) {
|
|
assert.throws(
|
|
() => parseRegionalRehomeInventory(
|
|
[{ timestamp: '2026-08-14T11:59:00Z', textPayload: complete + extra }],
|
|
{ now }
|
|
),
|
|
/no aggregate/,
|
|
extra
|
|
)
|
|
}
|
|
})
|
|
|
|
test('refuses a line missing a required field, or repeating one', () => {
|
|
const missing =
|
|
'[orca-relay] regional rehome inventory active=0 awaitingReceipt=0 targetRegistered=0' +
|
|
' completedLast24Hours=0 oldestActiveAgeMs=none'
|
|
assert.throws(
|
|
() => parseRegionalRehomeInventory(
|
|
[{ timestamp: '2026-08-14T11:59:00Z', textPayload: missing }],
|
|
{ now }
|
|
),
|
|
/no aggregate/
|
|
)
|
|
assert.throws(
|
|
() => parseRegionalRehomeInventory(
|
|
[{ timestamp: '2026-08-14T11:59:00Z', textPayload: `${missing} abortedLast24Hours=0 abortedLast24Hours=1` }],
|
|
{ now }
|
|
),
|
|
/no aggregate/
|
|
)
|
|
assert.throws(
|
|
() => parseRegionalRehomeInventory(
|
|
[{
|
|
timestamp: '2026-08-14T11:59:00Z',
|
|
textPayload: missing.replace('active=0', 'active=none') + ' abortedLast24Hours=0'
|
|
}],
|
|
{ now }
|
|
),
|
|
/no aggregate/
|
|
)
|
|
})
|
|
|
|
// The third edge of the chain the enable workflow depends on. The formatter is
|
|
// pinned against this parser in the relay package's inventory-line census; this
|
|
// pins the parser against the summary an operator reads, so a field that
|
|
// reaches the evidence JSON and stops there fails here.
|
|
test('publishes every parsed counter in the operator step summary', () => {
|
|
const job = readRelayWorkflow('operate-relay-production-rehome-job.yml')
|
|
// The jq program and the file it reads sit on separate continuation lines, so
|
|
// match the whole render rather than one line of it.
|
|
const summary = /jq -r '([^']*)' \\\n\s*"\$\{RUNNER_TEMP\}\/relay-rehome-inventory\.json"/.exec(job)?.[1]
|
|
assert.ok(summary, 'the rehome job no longer renders the inventory evidence')
|
|
const evidence = parseRegionalRehomeInventory([{
|
|
timestamp: '2026-08-14T11:58:00Z',
|
|
textPayload:
|
|
'[orca-relay] regional rehome inventory active=0 awaitingReceipt=0 targetRegistered=0' +
|
|
' completedLast24Hours=0 abortedLast24Hours=0 hostNotArrivedLast24Hours=0 oldestActiveAgeMs=none'
|
|
}], { now, maxAgeMs: 5 * 60_000 })
|
|
for (const key of Object.keys(evidence)) {
|
|
if (key === 'timestamp') continue
|
|
assert.ok(summary.includes(`.${key}`), `${key} is missing from the step summary`)
|
|
}
|
|
})
|