feat(n7web): sync N7 scene cards and optimize runtime
This commit is contained in:
@@ -310,6 +310,11 @@ const context = {
|
||||
setModeRailSelection(mode) { calls.push(["select", mode?.id]); },
|
||||
closeModeGallery(options) { calls.push(["close", options.restoreFocus]); },
|
||||
showToast(message) { calls.push(["toast", message]); },
|
||||
hasExecutableModeCommandFlow(mode) {
|
||||
const flow = mode?.command_flow;
|
||||
return Boolean(flow?.source_request_id)
|
||||
|| Boolean(flow?.plans && Object.keys(flow.plans).length);
|
||||
},
|
||||
executeSavedModeProfile(mode, options) {
|
||||
calls.push(["execute", mode.id, options.command]);
|
||||
return Promise.resolve(true);
|
||||
@@ -346,6 +351,42 @@ console.log(JSON.stringify({
|
||||
assert "executeSavedModeProfile" in snippet
|
||||
|
||||
|
||||
def test_n7_mode_command_flow_is_directly_executable_without_source_request_id() -> None:
|
||||
app = (WEB / "app.js").read_text(encoding="utf-8")
|
||||
start = app.index("function hasExecutableModeCommandFlow")
|
||||
end = app.index("\n\nasync function executeSavedModeProfile", start)
|
||||
helper = app[start:end]
|
||||
script = helper + r"""
|
||||
console.log(JSON.stringify({
|
||||
imported: hasExecutableModeCommandFlow({
|
||||
id: "cinema",
|
||||
command_flow: {
|
||||
source_topic: "from_n7/scenes",
|
||||
plans: { from_n7_scene: { spec: { commands: [] } } },
|
||||
},
|
||||
}),
|
||||
generated: hasExecutableModeCommandFlow({
|
||||
id: "reading-user",
|
||||
command_flow: { source_request_id: "req-reading" },
|
||||
}),
|
||||
missing: hasExecutableModeCommandFlow({ id: "office" }),
|
||||
}));
|
||||
"""
|
||||
completed = subprocess.run(
|
||||
[node_runtime(), "-e", script],
|
||||
check=True,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
assert json.loads(completed.stdout) == {
|
||||
"imported": True,
|
||||
"generated": True,
|
||||
"missing": False,
|
||||
}
|
||||
|
||||
|
||||
def test_mode_card_without_saved_flow_falls_back_to_assistant_submission() -> None:
|
||||
app = (WEB / "app.js").read_text(encoding="utf-8")
|
||||
start = app.index("function applyModeCommand")
|
||||
@@ -378,6 +419,11 @@ const context = {
|
||||
setModeExecutionState(modeId, status) { calls.push(["state", modeId, status]); },
|
||||
closeModeGallery(options) { calls.push(["close", options.restoreFocus]); },
|
||||
showToast(message) { calls.push(["toast", message]); },
|
||||
hasExecutableModeCommandFlow(mode) {
|
||||
const flow = mode?.command_flow;
|
||||
return Boolean(flow?.source_request_id)
|
||||
|| Boolean(flow?.plans && Object.keys(flow.plans).length);
|
||||
},
|
||||
$(selector) {
|
||||
return { "#utterance": input, "#requestForm": form, "#runButton": runButton }[selector];
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user