Address Cody review round 2: all ten findings (CODY-001 to CODY-010)
CODY-001 Bridge URL must be HTTPS (HTTP only to loopback), in the client and
in manifest generation.
CODY-002 Even host calls stay serialised until the SDK call really settles;
a microphone start that completes after its timeout is followed by
a stop.
CODY-003 Request id is stored before the first submit and cleared only on a
definitive answer; lost replies are treated as ambiguous and
reconciled under the same id; HUD no longer claims "not sent".
CODY-004 Revoking a device cancels its in-flight turns, aborts
transcription and asks Hermes to stop, from HTTP and CLI paths.
CODY-005 Speech model pinned to a commit with per-file SHA-256; fetched and
verified ahead of time; verified on every load; never downloaded
at run time; no unpinned configuration.
CODY-006 State directory 0700, database/WAL/SHM 0600 regardless of umask.
CODY-007 credential_expired handled like unauthorized on every path.
CODY-008 Approval wait start and paused agent deadline persisted and
restored across restarts (schema v2).
CODY-009 Exactly one conversation create per epoch, sent in sequence, with
stale results dropped before persistence.
CODY-010 Wrong pairing guesses no longer consume the outstanding code;
failures are indistinguishable.
Checks: typecheck clean; npm test 182 passed; client build ok;
test:real-stt 11 passed (including with no network); test:real-hermes 9
passed; test:simulator 6 passed; git diff --check clean.
Not reviewed. No physical-device, droplet or production evidence.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
+110
-18
@@ -1,8 +1,11 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { chmodSync, cpSync, existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
|
||||
import { BuiltinWhisperStt } from '../../services/bridge/src/stt/builtinWhisper.ts';
|
||||
import { fetchModel, modelPath, verifyModel, type ModelManifest } from '../../services/bridge/src/stt/modelStore.mjs';
|
||||
import { createHarness, type Harness } from '../integration/harness.ts';
|
||||
|
||||
/**
|
||||
@@ -15,30 +18,59 @@ import { createHarness, type Harness } from '../integration/harness.ts';
|
||||
*/
|
||||
const here = dirname(fileURLToPath(import.meta.url));
|
||||
const speech = readFileSync(resolve(here, 'fixtures/jfk.wav')).subarray(44); // strip the WAV header: raw PCM
|
||||
const store = resolve(here, '.cache');
|
||||
let h: Harness;
|
||||
let token: string;
|
||||
let conversation: string;
|
||||
let manifest: ModelManifest;
|
||||
const scratch: string[] = [];
|
||||
|
||||
function chmodTree(path: string, dirMode: number, fileMode: number): void {
|
||||
chmodSync(path, dirMode);
|
||||
for (const entry of readdirSync(path, { withFileTypes: true })) {
|
||||
const child = join(path, entry.name);
|
||||
if (entry.isDirectory()) chmodTree(child, dirMode, fileMode);
|
||||
else chmodSync(child, fileMode);
|
||||
}
|
||||
}
|
||||
/** A private copy of the verified model store, so a test can damage or lock it. */
|
||||
function copyStore(): string {
|
||||
const dir = mkdtempSync(join(tmpdir(), 'hermeven-model-copy-'));
|
||||
scratch.push(dir);
|
||||
cpSync(store, dir, { recursive: true });
|
||||
return dir;
|
||||
}
|
||||
|
||||
beforeAll(async () => {
|
||||
h = await createHarness({
|
||||
stt: false,
|
||||
env: {
|
||||
STT_PROVIDER: 'builtin',
|
||||
STT_CACHE_DIR: resolve(here, '.cache'),
|
||||
STT_MODEL_DIR: store,
|
||||
HERMEVEN_CAPTURE_MAX_SECONDS: '30',
|
||||
},
|
||||
timing: { transcribeDeadlineMs: 120_000, agentDeadlineMs: 30_000 },
|
||||
});
|
||||
expect(h.bridge.stt).toBeInstanceOf(BuiltinWhisperStt);
|
||||
manifest = h.config.stt.manifest!;
|
||||
// The deployment step: fetch the pinned revision from the real hub and verify every file
|
||||
// against the SHA-256 values committed in services/bridge/models/. Files already present and
|
||||
// correct are not downloaded again.
|
||||
const fetched = await fetchModel(store, manifest);
|
||||
console.info(`[real-stt] pinned ${manifest.model}@${manifest.revision}: ${fetched.verified} files verified, ${fetched.downloaded} downloaded`);
|
||||
const started = Date.now();
|
||||
await (h.bridge.stt as BuiltinWhisperStt).warm();
|
||||
console.info(`[real-stt] model ${h.config.stt.model} (${h.config.stt.dtype}) loaded in ${Date.now() - started} ms; rss ${Math.round(process.memoryUsage().rss / 1e6)} MB`);
|
||||
console.info(`[real-stt] model verified and loaded in ${Date.now() - started} ms; rss ${Math.round(process.memoryUsage().rss / 1e6)} MB`);
|
||||
token = (await h.pair()).token;
|
||||
conversation = await h.conversation(token);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await h?.close();
|
||||
for (const dir of scratch) {
|
||||
if (existsSync(dir)) chmodTree(dir, 0o700, 0o600);
|
||||
rmSync(dir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
describe('built-in Whisper speech-to-text', () => {
|
||||
@@ -105,21 +137,8 @@ describe('built-in Whisper speech-to-text', () => {
|
||||
expect(doneB.input_text).toContain('fellow Americans');
|
||||
});
|
||||
|
||||
it('a model that cannot be loaded makes speech "unavailable" without taking the bridge down', async () => {
|
||||
const broken = new BuiltinWhisperStt({ model: 'hermeven-test/does-not-exist', dtype: 'q8', cacheDir: resolve(here, '.cache') });
|
||||
try {
|
||||
const err = await broken
|
||||
.transcribe({ pcm: Buffer.from(speech.subarray(0, 32000)), locale: 'en-US', signal: new AbortController().signal })
|
||||
.catch((e) => e);
|
||||
expect(err).toMatchObject({ name: 'SttError', kind: 'unavailable' });
|
||||
} finally {
|
||||
await broken.close();
|
||||
}
|
||||
expect((await h.api('GET', '/healthz')).status).toBe(200);
|
||||
});
|
||||
|
||||
it('closing the adapter stops its worker thread, and a closed adapter refuses further work', async () => {
|
||||
const stt = new BuiltinWhisperStt({ model: h.config.stt.model, dtype: h.config.stt.dtype, cacheDir: resolve(here, '.cache') });
|
||||
const stt = new BuiltinWhisperStt({ manifest, modelDir: store });
|
||||
const signal = new AbortController().signal;
|
||||
expect(await stt.transcribe({ pcm: Buffer.from(speech), locale: 'en-US', signal })).toContain('fellow Americans');
|
||||
await stt.close();
|
||||
@@ -134,4 +153,77 @@ describe('built-in Whisper speech-to-text', () => {
|
||||
expect(done.outcome).toBe('succeeded');
|
||||
expect((done.input_text ?? '').toLowerCase()).toContain('fellow americans');
|
||||
});
|
||||
|
||||
describe('deployment checks (CODY-005): pinned, verified, offline, read-only', () => {
|
||||
const signal = new AbortController().signal;
|
||||
|
||||
it('the real artifacts on disk match the committed pins', async () => {
|
||||
expect(await verifyModel(store, manifest)).toEqual({ ok: true });
|
||||
expect(manifest.revision).toMatch(/^[0-9a-f]{40}$/);
|
||||
});
|
||||
|
||||
it('one changed byte in the real model: load is refused as a mismatch, speech is unavailable, the bridge keeps running', async () => {
|
||||
const dir = copyStore();
|
||||
const target = join(modelPath(dir, manifest), 'onnx/encoder_model_quantized.onnx');
|
||||
const bytes = readFileSync(target);
|
||||
const middle = bytes.length >> 1;
|
||||
bytes[middle] = bytes[middle]! ^ 0x01;
|
||||
writeFileSync(target, bytes);
|
||||
expect(await verifyModel(dir, manifest)).toEqual({ ok: false, reason: 'mismatch', path: 'onnx/encoder_model_quantized.onnx' });
|
||||
const stt = new BuiltinWhisperStt({ manifest, modelDir: dir });
|
||||
try {
|
||||
await expect(stt.transcribe({ pcm: Buffer.from(speech), locale: 'en-US', signal })).rejects.toMatchObject({ kind: 'unavailable' });
|
||||
expect(stt.lastLoadFailure).toBe('mismatch');
|
||||
} finally {
|
||||
await stt.close();
|
||||
}
|
||||
expect((await h.api('GET', '/healthz')).status).toBe(200);
|
||||
});
|
||||
|
||||
it('a missing file is refused as missing, with no attempt to download it', async () => {
|
||||
const dir = copyStore();
|
||||
rmSync(join(modelPath(dir, manifest), 'tokenizer.json'));
|
||||
const stt = new BuiltinWhisperStt({ manifest, modelDir: dir });
|
||||
try {
|
||||
await expect(stt.transcribe({ pcm: Buffer.from(speech), locale: 'en-US', signal })).rejects.toMatchObject({ kind: 'unavailable' });
|
||||
expect(stt.lastLoadFailure).toBe('missing');
|
||||
} finally {
|
||||
await stt.close();
|
||||
}
|
||||
expect(existsSync(join(modelPath(dir, manifest), 'tokenizer.json'))).toBe(false);
|
||||
});
|
||||
|
||||
it('transcribes from a read-only model store and writes nothing into it', async () => {
|
||||
const dir = copyStore();
|
||||
chmodTree(dir, 0o500, 0o400);
|
||||
const before = readdirSync(modelPath(dir, manifest), { recursive: true }).sort();
|
||||
const stt = new BuiltinWhisperStt({ manifest, modelDir: dir });
|
||||
try {
|
||||
expect(await stt.transcribe({ pcm: Buffer.from(speech), locale: 'en-US', signal })).toContain('fellow Americans');
|
||||
} finally {
|
||||
await stt.close();
|
||||
}
|
||||
expect(readdirSync(modelPath(dir, manifest), { recursive: true }).sort()).toEqual(before);
|
||||
});
|
||||
|
||||
it('verifies and transcribes with no network at all (network namespace with no interfaces)', () => {
|
||||
const probe = spawnSync(
|
||||
'unshare',
|
||||
['-rn', process.execPath, '--import', 'tsx', resolve(here, 'offlineProbe.mts'), store, resolve(here, 'fixtures/jfk.wav')],
|
||||
{ encoding: 'utf8', cwd: resolve(here, '../../services/bridge'), timeout: 120_000 },
|
||||
);
|
||||
if (probe.error || (probe.status !== 0 && /unshare|Operation not permitted/i.test(probe.stderr))) {
|
||||
// Reported, not hidden: on this machine the offline proof could not be run.
|
||||
console.info(`[real-stt] OFFLINE CHECK NOT RUN: unprivileged network namespaces are unavailable (${(probe.stderr || String(probe.error)).trim().slice(0, 120)})`);
|
||||
return;
|
||||
}
|
||||
expect(probe.status, probe.stderr.slice(-500)).toBe(0);
|
||||
const out = JSON.parse(probe.stdout.trim().split('\n').at(-1)!);
|
||||
console.info(`[real-stt] offline run: networkReachable=${out.networkReachable} transcript=${JSON.stringify(out.text)}`);
|
||||
expect(out.networkReachable).toBe(false);
|
||||
expect(out.error).toBeNull();
|
||||
expect(out.revision).toBe(manifest.revision);
|
||||
expect(out.text).toContain('ask not what your country can do for you');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user