[grade=B] fix(DC-163 rev2): strict merge semantics, contract-proving settings/test, valid enginecheck fixture
Judge r1 (C) blockers B1-B3 + polish both applied — see body of rev1 commit for feature scope. urn:ump:l2tg66wmchkmd6fde4k3ojwc56zpxqh657spe37bu6dpvduswalq
This commit is contained in:
2 files changed
+71
-11
No files matched your search
@@ -180,6 +180,27 @@ describe('DC-163 classify engine selection', () => {
|
||||
expect(out.appId).toBe('uptime-kuma'); // NOT in the old regex list — catalog-wide
|
||||
});
|
||||
|
||||
test('LLM reroute: pattern deploy result + LLM unknown → action null, stale appId dropped', async () => {
|
||||
// Judge r1 blocker #1: when the LLM overrides the pattern's intent,
|
||||
// NO intent-specific field from the pattern may ride along.
|
||||
const cm = fakeCredStore(JSON.stringify({ baseUrl: 'http://llm.test/v1', apiKey: '***', model: 'test-model' }));
|
||||
const out = await intentMod.classify({
|
||||
message: 'Deploy Plex', // pattern: deploy + appId plex
|
||||
history: [],
|
||||
deps: { credentialManager: cm, env: {}, fetchImpl: llmReplyFetch('{"intent":"rm -rf","appId":"plex","reply":"hmm"}'), log: silentLog, timeoutMs: 5000 },
|
||||
});
|
||||
expect(out.engine).toBe('llm');
|
||||
expect(out.intent).toBe('unknown'); // illegal value coerced
|
||||
// action must be strictly null (unknown has no action) — never the
|
||||
// pattern's deploy action riding along
|
||||
expect(out.action).toBeNull();
|
||||
// stale pattern appId must NOT be carried under the new intent
|
||||
expect(out.appId === undefined || out.appId === null).toBe(true);
|
||||
const enriched = intentMod.enrich(out);
|
||||
expect(enriched.response.message).toBeTruthy(); // rebuilt for unknown, no deployPlan
|
||||
expect(enriched.deployPlan).toBeUndefined();
|
||||
});
|
||||
|
||||
test('LLM disagreement: pattern said recommend, LLM says deploy → deploy response rebuilt', async () => {
|
||||
const cm = fakeCredStore(JSON.stringify({ baseUrl: 'http://llm.test/v1', apiKey: LLM_TEST_KEY }));
|
||||
const out = await intentMod.classify({
|
||||
@@ -352,6 +373,23 @@ describe('DC-163 ai HTTP routes', () => {
|
||||
} finally { server.close(); }
|
||||
});
|
||||
|
||||
test('POST /ai/settings/test — sample MUST classify as backup; coerced unknown = failure', async () => {
|
||||
// Judge r1 blocker #2: accepting a coerced 'unknown' would let a model
|
||||
// that ignores our prompt "pass" the test. Strict expectation now.
|
||||
const cm = fakeCredStore(JSON.stringify({ baseUrl: 'http://llm.test/v1', apiKey: LLM_TEST_KEY, model: 'test-model' }));
|
||||
const fetchImpl = llmReplyFetch('{"intent":"chitchat","appId":null,"reply":"lol sure"}'); // illegal -> coerces to unknown
|
||||
const app = buildRouter({ credentialManager: cm, fetchImpl });
|
||||
const { server, base } = await start(app);
|
||||
try {
|
||||
const res = await fetch(`${base}/ai/settings/test`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: '{}' });
|
||||
const body = await res.json();
|
||||
expect(res.status).toBe(200);
|
||||
expect(body.ok).toBe(false);
|
||||
expect(body.engine).toBe('llm-error');
|
||||
expect(body.reason).toMatch(/expected 'backup', got 'unknown'/);
|
||||
} finally { server.close(); }
|
||||
});
|
||||
|
||||
test('GET /ai/capabilities — engine reflects live configuration', async () => {
|
||||
const app = buildRouter();
|
||||
const { server, base } = await start(app);
|
||||
|
||||
Reference in new issue
Block a user