Files
kuentagym/api/test/adapters.test.js
T
Duarte Santos 5fb237682b Coach: der Fall ohne Vorgeschichte, und was der Validator durchgelassen hat
common.md wird jedem Prompt vorangestellt, also galt Regel 5 -- "jede
Begruendung nennt das, was in ihren Daten dafuer sprach" -- auch beim ersten
Plan fuer jemanden, der noch nichts geloggt hat. Da gibt es nichts zu nennen,
und die Regel hat das Modell genau dorthin gedraengt, wo es sich etwas
ausdenkt. Neu steht dabei, worauf man sich stattdessen beruft: Ziel, Erfahrung,
Tage, Ausruestung, Einschraenkungen -- und dass ein fehlendes window kein
Fehler ist. review.md sagt jetzt ausserdem, dass ohne Sessions die ehrliche
Antwort nochange ist, statt einen Grund zu erfinden.

repsMax stand im Validator, aber in keiner Tabelle -- das Modell konnte einen
Typ nicht verwenden, den wir akzeptieren.

payload.js laesst history ganz weg, wenn nichts mit Gewicht geloggt ist. Damit
lief die FR-20-Deckelung ins Leere und ein erfundenes Startgewicht ging
unveraendert an einen Anfaenger durch. Ohne Vergleichswerte fliegt weight jetzt
raus; die erste Session setzt die Basis, so wie create.md es ohnehin verspricht.

Dazu vier Luecken, die alle dieselbe Form haben -- etwas wird gezaehlt oder
gesetzt, aber nicht auf Eindeutigkeit geprueft:

- Zwei Routinen mit derselben id: known ist ein Set, die Woche validierte,
  ohne dass feststand, welche der beiden gemeint ist.
- Dieselbe Uebung zweimal in einer Routine: danach ist jedes reorder
  unerfuellbar (es verlangt jede id genau einmal) und jede gezielte Aenderung
  trifft die erste Kopie.
- Eine leere Woche uebersprang die Tagesanzahl-Pruefung ganz: "vier Tage" wurde
  mit einem Plan beantwortet, der gar nichts einplant.
- inc war nach oben offen.

add-routine trug ausserdem repsMin, prog und inc nicht mit, obwohl der
Bundle-Pfad sie kennt.

Die drei Codex-Flags sind aus invoke() in ein exportiertes argvFor()
gewandert und werden jetzt beim Wert geprueft. Sie waren vorher nirgends
getestet -- eines davon zu loeschen war ein gruener Build.
2026-08-18 23:20:05 +02:00

87 lines
4.7 KiB
JavaScript

/* The provider adapters, and the four options that make the Claude one safe.
*
* These assertions are deliberately about the object the adapter passes to the SDK rather than
* about observed model behaviour: the point is that re-enabling a tool is a red build, and a
* test that needed a real account to run would never guard anything in CI.
*/
import test from 'node:test';
import assert from 'node:assert/strict';
import { tempData } from './helpers.mjs';
tempData();
const { adapterFor, default: ADAPTERS } = await import('../coach/adapters/index.js');
const { LOCKDOWN } = await import('../coach/adapters/claude.js');
const { argvFor } = await import('../coach/adapters/codex.js');
const cfg = await import('../coach/config.js');
test('every provider the config offers has an adapter, and vice versa', () => {
assert.deepEqual(Object.keys(ADAPTERS).sort(), Object.keys(cfg.PROVIDERS).sort());
for (const id of Object.keys(cfg.PROVIDERS)) assert.ok(adapterFor(id), `no adapter for "${id}"`);
assert.equal(adapterFor('not-a-provider'), null);
});
test('the Claude adapter is locked out of every tool the SDK could give it', () => {
// `tools: []` is the SDK's documented "disable all built-in tools" — no Read, no Bash, no
// Grep — and the other three stop anything on the host widening that afterwards. If one of
// these ever has to change, it should be a decision with a diff, not a default that drifted.
assert.deepEqual(LOCKDOWN.tools, [], 'no built-in tools');
assert.deepEqual(LOCKDOWN.settingSources, [], 'no settings files may be loaded');
assert.deepEqual(LOCKDOWN.skills, [], 'no skills may be loaded');
assert.equal(LOCKDOWN.strictMcpConfig, true, 'no MCP server may arrive from ambient config');
assert.equal(LOCKDOWN.persistSession, false, 'no session history is written anywhere');
assert.equal(LOCKDOWN.maxTurns, 1, 'one turn: a job is a question, not a conversation');
});
test('an image built without the AI runtime reports it rather than crashing', async () => {
// The default build target has no SDK. check() is what the admin card renders, and it has to
// answer honestly on both targets — this asserts the shape either way, so the test is not
// hostage to which target the suite happens to run on.
const r = await adapterFor('claude').check();
assert.equal(typeof r.ok, 'boolean');
if (r.ok) assert.match(r.version, /Claude Agent SDK/);
else assert.match(r.error, /not installed/);
});
test('the fixture provider needs no credential and the Claude one names both it accepts', () => {
assert.equal(cfg.PROVIDERS.fixture.apiKeyEnv, null);
assert.equal(cfg.PROVIDERS.fixture.oauthEnv, null);
// The two variables the runtime reads. jobEnv() injects the credential under one of them and
// nothing else, which is what makes the sanitised environment the only channel it travels.
assert.equal(cfg.PROVIDERS.claude.oauthEnv, 'CLAUDE_CODE_OAUTH_TOKEN');
assert.equal(cfg.PROVIDERS.claude.apiKeyEnv, 'ANTHROPIC_API_KEY');
assert.equal(cfg.PROVIDERS.claude.setupToken, true);
});
test('the Codex credential cache is a sibling of ./data, never inside it', () => {
// The documented backup is `tar czf … data/`. A refresh token under ./data would ride along in
// every archive an owner is told to make, and keep working wherever that archive is copied.
const home = cfg.CREDENTIAL_HOME;
assert.ok(home, 'a provider that writes a credential cache needs somewhere to write it');
assert.equal(home.startsWith(process.env.DATA_DIR + '/'), false, `${home} is inside ./data`);
// …and it is actually handed to the runtime, under the variable that provider declares.
cfg.reset();
cfg.save({ enabled: true, provider: 'codex' });
assert.equal(cfg.jobEnv('/tmp/job', { ok: true }).CODEX_HOME, home);
// A provider with no cache of its own is given no such variable at all.
cfg.reset();
cfg.save({ enabled: true, provider: 'claude' });
assert.equal(cfg.jobEnv('/tmp/job', { ok: true }).CODEX_HOME, undefined);
});
test('the Codex adapter runs with the three flags that keep host state out of a job', () => {
// Same reasoning as the Claude lockdown above: these are not stylistic. --ignore-user-config
// stops $CODEX_HOME/config.toml being an admin-invisible input to every job, --ephemeral stops
// session files being written, and --skip-git-repo-check is what lets the bare mkdtemp job dir
// run at all. Dropping any of them was a green build before this test existed.
assert.deepEqual(argvFor(null), [
'exec', '-', '--skip-git-repo-check', '--ephemeral', '--ignore-user-config'
]);
});
test('a configured model is appended, and nothing else is', () => {
assert.deepEqual(argvFor('o4-mini').slice(-2), ['--model', 'o4-mini']);
assert.equal(argvFor('o4-mini').length, argvFor(null).length + 2);
});