feat: make mode creation preview-only and cache-safe

This commit is contained in:
Miayui
2026-09-20 19:32:03 +08:00
parent bfff1b515c
commit 89707a42e2
28 changed files with 1375 additions and 165 deletions
+18 -2
View File
@@ -138,7 +138,7 @@ function ndjsonResponse(events) {
};
}
function createHarness(events) {
function createHarness(events, executionMode = "dry_run") {
const document = new MockEventTarget();
const windowEvents = new MockEventTarget();
const body = new MockElement("body");
@@ -209,7 +209,7 @@ function createHarness(events) {
sandbox.removeEventListener = windowEvents.removeEventListener.bind(windowEvents);
sandbox.dispatchEvent = windowEvents.dispatchEvent.bind(windowEvents);
sandbox.CognitiveAgentConsole = {
getExecutionMode: () => "dry_run",
getExecutionMode: () => executionMode,
async refreshModeProfiles(modeProfileId) {
refreshedModeProfiles.push(modeProfileId);
},
@@ -367,6 +367,10 @@ test("assistant bridges request start and validated local controls to the consol
const cards = assistantArticle.querySelectorAll(".assistant-dispatched-controls");
assert.equal(cards.length, 1);
assert.equal(cards[0].open, true);
assert.equal(
cards[0].children[0].children[1].textContent,
"控制指令预览(未下发)",
);
assert.equal(
cards[0].querySelector(".assistant-dispatched-controls-count").textContent,
"3",
@@ -381,6 +385,7 @@ test("assistant bridges request start and validated local controls to the consol
["23°C", "关闭", "关闭"],
);
assert.match(rows[0].title, /实际控制指令:ac temp driver 23/);
assert.match(rows[0].title, /下发状态:仅预览 · 未下发/);
});
test("unsupported-control suggestions render once and click through as a new command", async () => {
@@ -544,6 +549,17 @@ function modeDraftEvents(sourceRequestId, temperatureC) {
];
}
test("mode creation always requests dry-run even while the console is in hardware mode", async () => {
const harness = createHarness(modeDraftEvents("req-draft-hardware-safe", 24), "hardware");
harness.input.value = "创建一个午休模式";
await harness.sandbox.CognitiveAgentAssistant.submit();
const request = JSON.parse(harness.requestCalls[0].options.body);
assert.equal(request.execution_mode, "dry_run");
assert.equal(Object.hasOwn(request, "hardware_client_id"), false);
});
test("a follow-up turn carries only the active authoritative draft reference", async () => {
const events = modeDraftEvents("req-draft-one", 24);
const harness = createHarness(events);