@niwa-labs/harness-zcode 0.0.0-stage → 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +8 -2
- package/package.json +20 -4
- package/scripts/gen-zcode.ts +384 -0
- package/src/config.ts +33 -0
- package/src/control.ts +1478 -0
- package/src/dispatch.ts +211 -0
- package/src/fixtures.ts +175 -0
- package/src/format.ts +153 -0
- package/src/index.ts +116 -0
- package/src/paths.ts +21 -0
- package/src/protocol/generated/zcode-protocol.ts +393 -0
- package/src/protocol/index.ts +230 -0
- package/src/reading.ts +506 -0
- package/src/reverse.ts +170 -0
- package/src/skills.ts +6 -0
- package/src/tools.ts +45 -0
- package/test/conformance.test.ts +29 -0
- package/test/control.test.ts +983 -0
- package/test/fixtures/zcode/captured-0.17.3.ndjson +23 -0
- package/test/fixtures/zcode/session-messages-0.17.3.json +241 -0
- package/test/live/control.test.ts +195 -0
- package/test/mode.test.ts +100 -0
- package/test/profile.test.ts +20 -0
- package/test/protocol.test.ts +437 -0
- package/test/reading.test.ts +332 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{"method":"startup/storageState","params":{"schemaVersion":1,"attemptId":"0be9b874-e315-443a-9970-6e6e25b79835","sequence":1,"databaseId":"ff2ecf0a15e4b13fae19118205c5c370e819278338f32bc6b251579ff6b7358e","databaseKind":"session","phase":"checking","elapsedMs":0}}
|
|
2
|
+
{"method":"session/lifecycle/changed","params":{"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","state":"starting","generation":1,"revision":1,"lastError":null}}
|
|
3
|
+
{"id":"server-1","method":"session/requestRuntimePreferences","params":{"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","scope":"runtime-materialization"}}
|
|
4
|
+
{"id":"server-2","method":"interaction/requestOfficialMcpAuthHeaders","params":{"mcpKey":"sites","pluginId":"zcode-site@zcode-plugins-official","requestId":"official-mcp-auth:1","targetOrigin":"https://zcode.z.ai","workspace":{"workspaceKey":"/tmp/zcap/work-LjZuhQ","workspacePath":"/tmp/zcap/work-LjZuhQ"}}}
|
|
5
|
+
{"method":"state.updated","params":{"patch":{"status":"running"},"reason":"prompt_started","revision":1,"scope":"session","sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","type":"state.updated","workspace":{"workspacePath":"/tmp/zcap/work-LjZuhQ","workspaceKey":"/tmp/zcap/work-LjZuhQ"}}}
|
|
6
|
+
{"method":"v4/conversation/contextCompositionChanged","params":{"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","revision":1}}
|
|
7
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"15ffa324-96cf-46e4-aa1b-17c396b0865e","payload":{"previousTitle":"","source":"first_input","title":"Run the shell command `echo capture-ok` with the Bash too..."},"seq":1,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130843728,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"session.titleUpdated"}}
|
|
8
|
+
{"method":"computer-use/operation-event","params":{"eventId":"7320d0b4-f232-443a-aeb3-e0ba679cb799","sequenceNumber":2,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130843815,"kind":"turn-started","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1"}}
|
|
9
|
+
{"method":"v4/telemetry/event","params":{"memoryEnabled":false,"version":1,"eventId":"7320d0b4-f232-443a-aeb3-e0ba679cb799","eventSeq":2,"occurredAt":1795130843815,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","kind":"turn.started","modelName":"minimax/MiniMax-M3","modelProvider":"2eafb73d-b2f6-45af-9d68-e81dcc8e53e1"}}
|
|
10
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"7320d0b4-f232-443a-aeb3-e0ba679cb799","payload":{"executionStartedAt":1795130843681.5925,"turnNumber":0,"input":"Run the shell command `echo capture-ok` with the Bash tool, then say done.","messageId":"msg_mwo6jzxj_5d7cb608-42b9-4c10-b77f-4049f884a1fa","foregroundExecutionId":"runtime_command_1","queryId":"query_4be64e3d-22b5-4994-8599-7df8f1796bc2"},"seq":2,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130843815,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"turn.started"}}
|
|
11
|
+
{"id":"server-4","method":"session/readReplyLanguage","params":{"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec"},"trace":{"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","spanId":"370c0f70-34c9-4b","parentId":"464ece3d-c1b1-42"}}
|
|
12
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"d97341d5-be6f-4217-b753-4ef7fbd441a5","payload":{"messageCount":10,"providerId":"2eafb73d-b2f6-45af-9d68-e81dcc8e53e1","modelId":"minimax/MiniMax-M3","toolCount":21,"iteration":0},"seq":3,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130844105,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"session.updated"}}
|
|
13
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"f61c330b-d85c-4490-be08-51a61cb7c9d5","payload":{"assistantMessageId":"msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8","delta":"I'll run","done":false,"kind":"text_delta"},"seq":5,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130846833,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"model.streaming"}}
|
|
14
|
+
{"method":"v4/telemetry/model-request-metrics","params":{"memoryEnabled":false,"version":1,"eventId":"dafd3e1d-5bd1-49db-a9d1-cb4e385deca3","eventSeq":16,"occurredAt":1795130847219,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","kind":"model.request.metrics","requestId":"eac3470f-0c82-40ec-92db-6aebc804eaa0","providerId":"2eafb73d-b2f6-45af-9d68-e81dcc8e53e1","modelId":"minimax/MiniMax-M3","querySource":"main_turn","queryId":"query_4be64e3d-22b5-4994-8599-7df8f1796bc2","durationMs":2704,"timeToFirstContentMs":2357,"inputTokens":14073,"outputTokens":48,"cacheReadTokens":128,"cacheWriteTokens":0,"totalTokens":14121}}
|
|
15
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"ce950275-447a-410c-aba0-cdbe20f4f944","payload":{"toolCallId":"call_8d97fea65ff0bb0175cee485","assistantMessageId":"msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8","toolName":"Bash","dependencies":[],"parallelGroupIndex":0,"canRunParallel":false,"schedule":{"parallelGroups":[["call_8d97fea65ff0bb0175cee485"]],"executionOrder":["call_8d97fea65ff0bb0175cee485"]},"kind":"scheduled","inputByteLength":61,"inputOmitted":true,"inputRef":"model_stream"},"seq":13,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130847679,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"tool.updated"}}
|
|
16
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"4945ad13-2111-49ce-b4ae-66f42c88621c","payload":{"anchorId":"msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8:call_8d97fea65ff0bb0175cee485:tool-result","attemptId":"msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8:end-of-stream","kind":"tool_result","assistantMessageId":"msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8","toolCallId":"call_8d97fea65ff0bb0175cee485","toolName":"Bash","resultPartId":"part_mwo6k2r3_5c6ac60e-d667-430c-a9ed-c2ebdb2853ae","committedToolCallIds":["call_8d97fea65ff0bb0175cee485"],"committedAt":"2026-11-19T23:27:31.743Z"},"seq":17,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130851758,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"streamRecovery.updated"}}
|
|
17
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"c81c4556-3c35-4161-aacc-f6eae8a3879f","payload":{"response":"Done — the command printed `capture-ok`.","tokenCount":28295,"usage":{"source":"provider","modelRequestCount":2,"inputTokens":28235,"outputTokens":60,"totalTokens":28295,"cacheReadTokens":14208,"cacheWriteTokens":0,"reasoningTokens":0,"webFetchRequests":0,"webSearchRequests":0},"toolCallCount":1,"historyRoundCount":2,"duration":9010,"resultType":"success","cacheStats":{"totalMessages":14,"cachedMessages":13,"lastCacheHit":true,"cacheReadTokens":14080}},"seq":24,"sessionId":"sess_c42e8179-b142-4431-9615-ebc1272159ec","timestamp":1795130852689,"traceId":"d33060e5-225a-4b4c-b945-a6053cb515f7","turnId":"turn_e20d85d3-f383-4141-93a6-3890750f9cb1","type":"turn.completed"}}
|
|
18
|
+
{"id":"server-5","method":"interaction/requestUserInput","params":{"input":{"questions":[{"question":"Which color do you prefer?","header":"Color","options":[{"label":"Red","description":"Write \"red\" into answer.txt"},{"label":"Blue","description":"Write \"blue\" into answer.txt"}],"multiSelect":false}]},"prompt":"Tool AskUserQuestion requires user interaction","questions":[{"header":"Color","multiSelect":false,"options":[{"description":"Write \"red\" into answer.txt","label":"Red","value":"Red"},{"description":"Write \"blue\" into answer.txt","label":"Blue","value":"Blue"}],"question":"Which color do you prefer?"}],"requestId":"perm_c960baa6-8c9c-4251-b4e0-251b70e3b6fa","schema":{"toolName":"AskUserQuestion"},"sessionId":"sess_311113fb-430d-4c56-8be3-93404ecdded8","toolCallId":"call_01a1f63319f574e596d65e2a","toolName":"AskUserQuestion","turnId":"turn_a27c6da4-8418-459f-946e-2e7b9b4af086"}}
|
|
19
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"afe5f284-93a9-4b5b-8174-54d834ff7220","payload":{"requestId":"perm_c960baa6-8c9c-4251-b4e0-251b70e3b6fa","toolCallId":"call_01a1f63319f574e596d65e2a","toolName":"AskUserQuestion","riskLevel":"low","reason":"Tool AskUserQuestion requires user interaction","input":{"questions":[{"question":"Which color do you prefer?","header":"Color","options":[{"label":"Red","description":"Write \"red\" into answer.txt"},{"label":"Blue","description":"Write \"blue\" into answer.txt"}],"multiSelect":false}]},"suggestedPermissionUpdates":[{"behavior":"allow","rules":[{"toolName":"AskUserQuestion"}],"type":"addRules"}],"options":[{"kind":"allow_once","name":"Allow once","optionId":"allow_once","response":{"decision":"allow","reason":"Approved once"}},{"description":"Do not ask again for matching requests in this project","kind":"allow_always","name":"Always allow in this project","optionId":"allow_project","response":{"decision":"allow","permissionUpdates":[{"behavior":"allow","rules":[{"toolName":"AskUserQuestion"}],"type":"addRules"}],"reason":"Approved for this project"}},{"kind":"deny","name":"Deny","optionId":"deny","response":{"decision":"deny","reason":"The user doesn't want to proceed with this tool use. The tool use was rejected (eg. if it was a file edit, the new_string was NOT written to the file). STOP what you are doing and wait for the user to tell you how to proceed."}}]},"seq":15,"sessionId":"sess_311113fb-430d-4c56-8be3-93404ecdded8","timestamp":1795131909426,"traceId":"5d99d461-1a53-4d13-b7f6-ce78de748226","turnId":"turn_a27c6da4-8418-459f-946e-2e7b9b4af086","type":"permission.requested"}}
|
|
20
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"e572d529-c9b0-4900-b19a-4b5d8a7477ef","payload":{"requestId":"perm_c960baa6-8c9c-4251-b4e0-251b70e3b6fa","toolCallId":"call_01a1f63319f574e596d65e2a","decision":"deny","reason":"niwa has no one to ask"},"seq":16,"sessionId":"sess_311113fb-430d-4c56-8be3-93404ecdded8","timestamp":1795131910445,"traceId":"5d99d461-1a53-4d13-b7f6-ce78de748226","turnId":"turn_a27c6da4-8418-459f-946e-2e7b9b4af086","type":"permission.resolved"}}
|
|
21
|
+
{"method":"process/mcpTelemetry","params":{"arch":"arm64","configuredCount":6,"connectedCount":0,"failedCount":6,"kind":"session_startup","occurredAt":1795131917281,"platform":"darwin","processCount":0,"sessionId":"sess_311113fb-430d-4c56-8be3-93404ecdded8"}}
|
|
22
|
+
{"method":"process/mcpTelemetry","params":{"arch":"arm64","kind":"process_start","mcpId":"builtin:documents:documents","mcpInstanceId":"7da62929-8416-4c2d-b41a-18f2f1466e4a","mcpIsolation":"workspace","mcpSource":"builtin","occurredAt":1795131917488,"platform":"darwin"}}
|
|
23
|
+
{"method":"session/event","params":{"deliveryKind":"desktop-continuous","eventId":"cb99b57d-37cb-433e-a7e1-d919f05a696c","payload":{"checkpointId":"checkpoint_5f88b88b-0a8c-47e5-b8fd-952d77b42ae0","messageId":"msg_mwo76q8i_bf6b5653-210d-49fb-a598-7fbf8defe47c","targetMessageId":"msg_mwo76q8i_bf6b5653-210d-49fb-a598-7fbf8defe47c","toolMessageId":"msg_mwo778bw_bbf47e0b-c53b-461c-a4a8-60f47581bbd6","scope":"workspace","snapshotRef":"zcode-artifact://sess_311113fb-430d-4c56-8be3-93404ecdded8/tool-result-6a0e661b-3528-4d7b-a09f-8c0095cc007f","diffRef":"zcode-artifact://sess_311113fb-430d-4c56-8be3-93404ecdded8/tool-result-6a0e661b-3528-4d7b-a09f-8c0095cc007f","fileCount":1},"seq":76,"sessionId":"sess_311113fb-430d-4c56-8be3-93404ecdded8","timestamp":1795131929772,"traceId":"5d99d461-1a53-4d13-b7f6-ce78de748226","turnId":"turn_a27c6da4-8418-459f-946e-2e7b9b4af086","type":"checkpoint.created"}}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
{
|
|
2
|
+
"messages": [
|
|
3
|
+
{
|
|
4
|
+
"info": {
|
|
5
|
+
"agent": "zcode-agent",
|
|
6
|
+
"messageId": "msg_mwo6jzxj_5d7cb608-42b9-4c10-b77f-4049f884a1fa",
|
|
7
|
+
"model": {
|
|
8
|
+
"providerId": "2eafb73d-b2f6-45af-9d68-e81dcc8e53e1",
|
|
9
|
+
"modelId": "minimax/MiniMax-M3",
|
|
10
|
+
"options": {
|
|
11
|
+
"reasoningLevel": "enabled"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"role": "user",
|
|
15
|
+
"semantics": {
|
|
16
|
+
"origin": "real_user",
|
|
17
|
+
"kind": "user_prompt",
|
|
18
|
+
"uiVisibility": "visible",
|
|
19
|
+
"providerVisibility": "visible",
|
|
20
|
+
"transcriptVisibility": "visible"
|
|
21
|
+
},
|
|
22
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
23
|
+
"time": {
|
|
24
|
+
"created": 1795130844028
|
|
25
|
+
},
|
|
26
|
+
"tools": {
|
|
27
|
+
"Agent": true,
|
|
28
|
+
"AskUserQuestion": true,
|
|
29
|
+
"Bash": true,
|
|
30
|
+
"CronCreate": true,
|
|
31
|
+
"CronDelete": true,
|
|
32
|
+
"CronList": true,
|
|
33
|
+
"CronUpdate": true,
|
|
34
|
+
"Edit": true,
|
|
35
|
+
"EnterPlanMode": true,
|
|
36
|
+
"ExitPlanMode": true,
|
|
37
|
+
"Read": true,
|
|
38
|
+
"SendMessage": true,
|
|
39
|
+
"Skill": true,
|
|
40
|
+
"TaskOutput": true,
|
|
41
|
+
"TaskStop": true,
|
|
42
|
+
"TodoRead": true,
|
|
43
|
+
"TodoWrite": true,
|
|
44
|
+
"ToolSearch": true,
|
|
45
|
+
"WebFetch": true,
|
|
46
|
+
"WebSearch": true,
|
|
47
|
+
"Write": true,
|
|
48
|
+
"SearchPlugins": true,
|
|
49
|
+
"SuggestPluginInstall": true,
|
|
50
|
+
"DeferredToolCall": true,
|
|
51
|
+
"CronPauseSelf": true,
|
|
52
|
+
"ReadTopicResource": true
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
"parts": [
|
|
56
|
+
{
|
|
57
|
+
"messageId": "msg_mwo6jzxj_5d7cb608-42b9-4c10-b77f-4049f884a1fa",
|
|
58
|
+
"partId": "part_mwo6k03g_66353059-08dd-4b3e-810f-149cd00f02aa",
|
|
59
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
60
|
+
"text": "Run the shell command `echo capture-ok` with the Bash tool, then say done.",
|
|
61
|
+
"type": "text"
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"info": {
|
|
67
|
+
"agent": "zcode-agent",
|
|
68
|
+
"cost": 0,
|
|
69
|
+
"finish": "tool-calls",
|
|
70
|
+
"messageId": "msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8",
|
|
71
|
+
"model": {
|
|
72
|
+
"providerId": "2eafb73d-b2f6-45af-9d68-e81dcc8e53e1",
|
|
73
|
+
"modelId": "minimax/MiniMax-M3"
|
|
74
|
+
},
|
|
75
|
+
"parentMessageId": "msg_mwo6jzxj_5d7cb608-42b9-4c10-b77f-4049f884a1fa",
|
|
76
|
+
"path": {
|
|
77
|
+
"cwd": "/tmp/zcap/work-LjZuhQ",
|
|
78
|
+
"root": "/tmp/zcap/work-LjZuhQ"
|
|
79
|
+
},
|
|
80
|
+
"role": "assistant",
|
|
81
|
+
"semantics": {
|
|
82
|
+
"origin": "agent_runtime",
|
|
83
|
+
"kind": "assistant_response",
|
|
84
|
+
"uiVisibility": "visible",
|
|
85
|
+
"providerVisibility": "visible",
|
|
86
|
+
"transcriptVisibility": "visible"
|
|
87
|
+
},
|
|
88
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
89
|
+
"time": {
|
|
90
|
+
"created": 1795130844099,
|
|
91
|
+
"completed": 1795130851761
|
|
92
|
+
},
|
|
93
|
+
"tokens": {
|
|
94
|
+
"total": 14121,
|
|
95
|
+
"input": 14073,
|
|
96
|
+
"output": 48,
|
|
97
|
+
"reasoning": 0,
|
|
98
|
+
"cache": {
|
|
99
|
+
"read": 128,
|
|
100
|
+
"write": 0
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"parts": [
|
|
105
|
+
{
|
|
106
|
+
"messageId": "msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8",
|
|
107
|
+
"partId": "part_mwo6k05h_c4aff73c-0335-491b-aa5a-1884958e5df5",
|
|
108
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
109
|
+
"type": "step-start"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"messageId": "msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8",
|
|
113
|
+
"partId": "part_mwo6k2qe_847c8677-de48-42e6-8c49-8e302b5a903c",
|
|
114
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
115
|
+
"text": "I'll run that command.",
|
|
116
|
+
"type": "text"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"messageId": "msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8",
|
|
120
|
+
"partId": "part_mwo6k2r3_5c6ac60e-d667-430c-a9ed-c2ebdb2853ae",
|
|
121
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
122
|
+
"callId": "call_8d97fea65ff0bb0175cee485",
|
|
123
|
+
"metadata": {},
|
|
124
|
+
"state": {
|
|
125
|
+
"completedAt": 1795130851743,
|
|
126
|
+
"input": {
|
|
127
|
+
"command": "echo capture-ok",
|
|
128
|
+
"description": "Echo capture-ok"
|
|
129
|
+
},
|
|
130
|
+
"metadata": {
|
|
131
|
+
"schemaVersion": 1,
|
|
132
|
+
"serialization": {
|
|
133
|
+
"truncated": false,
|
|
134
|
+
"originalBytes": 10,
|
|
135
|
+
"returnedBytes": 10,
|
|
136
|
+
"budgetStrategy": "artifact"
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
"output": "capture-ok",
|
|
140
|
+
"startedAt": 1795130847851,
|
|
141
|
+
"status": "completed",
|
|
142
|
+
"title": "Bash"
|
|
143
|
+
},
|
|
144
|
+
"tool": "Bash",
|
|
145
|
+
"type": "tool"
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
"messageId": "msg_mwo6k05e_237edbc4-410a-49ed-8de9-fd7c68fda6a8",
|
|
149
|
+
"partId": "part_mwo6k627_161c8968-5e45-4fed-9290-985c8d489448",
|
|
150
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
151
|
+
"cost": 0,
|
|
152
|
+
"reason": "tool-calls",
|
|
153
|
+
"tokens": {
|
|
154
|
+
"total": 14121,
|
|
155
|
+
"input": 14073,
|
|
156
|
+
"output": 48,
|
|
157
|
+
"reasoning": 0,
|
|
158
|
+
"cache": {
|
|
159
|
+
"read": 128,
|
|
160
|
+
"write": 0
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"type": "step-finish"
|
|
164
|
+
}
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
"info": {
|
|
169
|
+
"agent": "zcode-agent",
|
|
170
|
+
"cost": 0,
|
|
171
|
+
"finish": "stop",
|
|
172
|
+
"messageId": "msg_mwo6k62o_f0b6d703-e12c-40ff-ad63-cf432b1843be",
|
|
173
|
+
"model": {
|
|
174
|
+
"providerId": "2eafb73d-b2f6-45af-9d68-e81dcc8e53e1",
|
|
175
|
+
"modelId": "minimax/MiniMax-M3"
|
|
176
|
+
},
|
|
177
|
+
"parentMessageId": "msg_mwo6jzxj_5d7cb608-42b9-4c10-b77f-4049f884a1fa",
|
|
178
|
+
"path": {
|
|
179
|
+
"cwd": "/tmp/zcap/work-LjZuhQ",
|
|
180
|
+
"root": "/tmp/zcap/work-LjZuhQ"
|
|
181
|
+
},
|
|
182
|
+
"role": "assistant",
|
|
183
|
+
"semantics": {
|
|
184
|
+
"origin": "agent_runtime",
|
|
185
|
+
"kind": "assistant_response",
|
|
186
|
+
"uiVisibility": "visible",
|
|
187
|
+
"providerVisibility": "visible",
|
|
188
|
+
"transcriptVisibility": "visible"
|
|
189
|
+
},
|
|
190
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
191
|
+
"time": {
|
|
192
|
+
"created": 1795130851777,
|
|
193
|
+
"completed": 1795130852678
|
|
194
|
+
},
|
|
195
|
+
"tokens": {
|
|
196
|
+
"total": 14174,
|
|
197
|
+
"input": 14162,
|
|
198
|
+
"output": 12,
|
|
199
|
+
"reasoning": 0,
|
|
200
|
+
"cache": {
|
|
201
|
+
"read": 14080,
|
|
202
|
+
"write": 0
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
"parts": [
|
|
207
|
+
{
|
|
208
|
+
"messageId": "msg_mwo6k62o_f0b6d703-e12c-40ff-ad63-cf432b1843be",
|
|
209
|
+
"partId": "part_mwo6k62t_b1496927-5366-443d-87df-744b8f4cf777",
|
|
210
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
211
|
+
"type": "step-start"
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"messageId": "msg_mwo6k62o_f0b6d703-e12c-40ff-ad63-cf432b1843be",
|
|
215
|
+
"partId": "part_mwo6k6q1_439f2abe-cdad-4c58-836e-467f579abcba",
|
|
216
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
217
|
+
"text": "Done — the command printed `capture-ok`.",
|
|
218
|
+
"type": "text"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"messageId": "msg_mwo6k62o_f0b6d703-e12c-40ff-ad63-cf432b1843be",
|
|
222
|
+
"partId": "part_mwo6k6q7_6980c520-0d84-42ac-91d9-bd64934caaec",
|
|
223
|
+
"sessionId": "sess_c42e8179-b142-4431-9615-ebc1272159ec",
|
|
224
|
+
"cost": 0,
|
|
225
|
+
"reason": "stop",
|
|
226
|
+
"tokens": {
|
|
227
|
+
"total": 14174,
|
|
228
|
+
"input": 14162,
|
|
229
|
+
"output": 12,
|
|
230
|
+
"reasoning": 0,
|
|
231
|
+
"cache": {
|
|
232
|
+
"read": 14080,
|
|
233
|
+
"write": 0
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
"type": "step-finish"
|
|
237
|
+
}
|
|
238
|
+
]
|
|
239
|
+
}
|
|
240
|
+
]
|
|
241
|
+
}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// The ZCode control side and reading side, live.
|
|
2
|
+
//
|
|
3
|
+
// A real `zcode app-server` is started in a temporary directory and given a few tiny turns: a
|
|
4
|
+
// start with a prompt, a question answered by schema, and in a fresh process a resume, a send
|
|
5
|
+
// and an interrupt that cuts the turn. The session is then read back from ZCode's own database.
|
|
6
|
+
//
|
|
7
|
+
// The test is skipped unless NIWA_LIVE=1 and `zcode` is on the PATH. The model is the one the
|
|
8
|
+
// installation runs by default; `NIWA_ZCODE_MODEL` (`providerId/modelId`) and `NIWA_ZCODE_EFFORT`
|
|
9
|
+
// name another. Z.AI account models are injected by the desktop app and are not reachable from a
|
|
10
|
+
// standalone `zcode app-server`, so the default model is the one that works here.
|
|
11
|
+
|
|
12
|
+
import { expect, test } from "bun:test";
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { writeFile } from "node:fs/promises";
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
import { z } from "zod";
|
|
19
|
+
|
|
20
|
+
import { harnessId, promptFromText } from "@niwa-labs/harness";
|
|
21
|
+
import type { LifeEvent, SessionControl, SessionId, SessionRecord } from "@niwa-labs/harness";
|
|
22
|
+
import { live, tempDir } from "@niwa-labs/testing";
|
|
23
|
+
|
|
24
|
+
import { ZcodeReading } from "../../src/reading.ts";
|
|
25
|
+
import { zcodeControl } from "../../src/control.ts";
|
|
26
|
+
import type { ZcodeSessionControl } from "../../src/control.ts";
|
|
27
|
+
|
|
28
|
+
const installed = Bun.which("zcode") !== null;
|
|
29
|
+
const MODEL = process.env["NIWA_ZCODE_MODEL"];
|
|
30
|
+
const EFFORT = process.env["NIWA_ZCODE_EFFORT"];
|
|
31
|
+
const HARNESS = harnessId("zcode-live");
|
|
32
|
+
const HOME = join(homedir(), ".zcode");
|
|
33
|
+
|
|
34
|
+
/** How long one turn may take before the test gives up on it. */
|
|
35
|
+
const TURN_DEADLINE_MS = 240_000;
|
|
36
|
+
|
|
37
|
+
function control(): ZcodeSessionControl {
|
|
38
|
+
return zcodeControl({
|
|
39
|
+
harness: HARNESS,
|
|
40
|
+
home: HOME,
|
|
41
|
+
...(MODEL === undefined ? {} : { model: MODEL }),
|
|
42
|
+
...(EFFORT === undefined ? {} : { effort: EFFORT }),
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Watches the signs of life until a turn ends; the stream is forward-only, so this is called before the action. */
|
|
47
|
+
function turnEnded(side: SessionControl, id: SessionId): Promise<LifeEvent[]> {
|
|
48
|
+
const stream = side.life(id)[Symbol.asyncIterator]();
|
|
49
|
+
const seen: LifeEvent[] = [];
|
|
50
|
+
const watching = (async () => {
|
|
51
|
+
for (;;) {
|
|
52
|
+
const next = await stream.next();
|
|
53
|
+
if (next.done === true) throw new Error("the session ended before the turn did");
|
|
54
|
+
seen.push(next.value);
|
|
55
|
+
if (next.value.kind === "turn-ended") return seen;
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
const deadline = new Promise<never>((_, reject) => {
|
|
59
|
+
const timer = setTimeout(() => reject(new Error(`the turn did not end within ${TURN_DEADLINE_MS} ms`)), TURN_DEADLINE_MS);
|
|
60
|
+
void watching.finally(() => clearTimeout(timer)).catch(() => undefined);
|
|
61
|
+
});
|
|
62
|
+
return Promise.race([watching, deadline]).finally(() => void stream.return?.());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async function records(id: SessionId): Promise<SessionRecord[]> {
|
|
66
|
+
const out: SessionRecord[] = [];
|
|
67
|
+
for await (const record of new ZcodeReading({ harness: HARNESS, home: HOME }).read(id)) out.push(record);
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
test.skipIf(!live || !installed)(
|
|
72
|
+
"a real ZCode starts, answers by schema, resumes in a new process, and is interrupted",
|
|
73
|
+
async () => {
|
|
74
|
+
const cwd = await tempDir("live-zcode");
|
|
75
|
+
const first = control();
|
|
76
|
+
let session: SessionId | undefined;
|
|
77
|
+
try {
|
|
78
|
+
const started = await first.start({ prompt: promptFromText("Reply with the single word ok."), cwd });
|
|
79
|
+
session = started.session;
|
|
80
|
+
expect(String(session.native)).toMatch(/^sess_/);
|
|
81
|
+
expect(started.first?.status).toBe("started");
|
|
82
|
+
const signs = await turnEnded(first, session);
|
|
83
|
+
expect(signs.some((event) => event.kind === "turn-started")).toBe(true);
|
|
84
|
+
|
|
85
|
+
const answer = await first.ask(session, {
|
|
86
|
+
schema: z.object({ word: z.string() }),
|
|
87
|
+
prompt: promptFromText('Reply with the JSON {"word": "ok"}'),
|
|
88
|
+
});
|
|
89
|
+
expect(answer.value.word.toLowerCase()).toContain("ok");
|
|
90
|
+
|
|
91
|
+
// The session is in ZCode's database once a turn has completed, and the reading side finds the conversation there.
|
|
92
|
+
const read = await records(session);
|
|
93
|
+
expect(read.some((record) => record.kind === "user" && record.text.includes("single word ok"))).toBe(true);
|
|
94
|
+
expect(read.some((record) => record.kind === "assistant")).toBe(true);
|
|
95
|
+
expect(read.every((record) => !record.incomplete)).toBe(true);
|
|
96
|
+
} finally {
|
|
97
|
+
await first.dispose();
|
|
98
|
+
}
|
|
99
|
+
if (session === undefined) throw new Error("the session was never named");
|
|
100
|
+
|
|
101
|
+
// A fresh process takes the session up by its id; a message begins a turn, and the interrupt cuts it.
|
|
102
|
+
const second = control();
|
|
103
|
+
try {
|
|
104
|
+
await second.resume(session);
|
|
105
|
+
const ended = turnEnded(second, session);
|
|
106
|
+
const receipt = await second.send(session, "Write the numbers from 1 to 400, one per line, with no other text.");
|
|
107
|
+
expect(receipt.status).toBe("started");
|
|
108
|
+
await second.interrupt(session);
|
|
109
|
+
const signs = await ended;
|
|
110
|
+
expect(signs.some((event) => event.kind === "turn-ended")).toBe(true);
|
|
111
|
+
expect(await second.state(session)).toBe("idle");
|
|
112
|
+
} finally {
|
|
113
|
+
await second.dispose();
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
TURN_DEADLINE_MS * 3,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* A stdio MCP server of one tool, `niwa_probe`: it writes `probe.called` next to itself when the
|
|
121
|
+
* tool is called, so the test knows the call came from the session, whatever the model then says.
|
|
122
|
+
*/
|
|
123
|
+
const PROBE_SERVER = `
|
|
124
|
+
import { writeFileSync } from "node:fs";
|
|
125
|
+
import { join } from "node:path";
|
|
126
|
+
const reply = (id, result) => process.stdout.write(JSON.stringify({ jsonrpc: "2.0", id, result }) + "\\n");
|
|
127
|
+
let buffer = "";
|
|
128
|
+
process.stdin.on("data", (chunk) => {
|
|
129
|
+
buffer += chunk;
|
|
130
|
+
for (let at = buffer.indexOf("\\n"); at >= 0; at = buffer.indexOf("\\n")) {
|
|
131
|
+
const line = buffer.slice(0, at);
|
|
132
|
+
buffer = buffer.slice(at + 1);
|
|
133
|
+
if (line.trim() === "") continue;
|
|
134
|
+
const message = JSON.parse(line);
|
|
135
|
+
if (message.id === undefined) continue;
|
|
136
|
+
if (message.method === "initialize") {
|
|
137
|
+
reply(message.id, { protocolVersion: message.params?.protocolVersion ?? "2025-06-18", capabilities: { tools: {} }, serverInfo: { name: "probe", version: "1" } });
|
|
138
|
+
} else if (message.method === "tools/list") {
|
|
139
|
+
reply(message.id, { tools: [{ name: "niwa_probe", description: "Call this tool to prove the server is connected. Takes no arguments.", inputSchema: { type: "object", properties: {} } }] });
|
|
140
|
+
} else if (message.method === "tools/call") {
|
|
141
|
+
writeFileSync(join(import.meta.dir, "probe.called"), "yes");
|
|
142
|
+
reply(message.id, { content: [{ type: "text", text: "probe-ok" }] });
|
|
143
|
+
} else {
|
|
144
|
+
reply(message.id, {});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
test.skipIf(!live || !installed)(
|
|
151
|
+
"a real ZCode is given an MCP server at its start, and calls the tool of it",
|
|
152
|
+
async () => {
|
|
153
|
+
const cwd = await tempDir("live-zcode-mcp");
|
|
154
|
+
const script = join(cwd, "probe-server.ts");
|
|
155
|
+
await writeFile(script, PROBE_SERVER);
|
|
156
|
+
const side = control();
|
|
157
|
+
try {
|
|
158
|
+
const started = await side.start({
|
|
159
|
+
prompt: promptFromText("Call the tool niwa_probe of the MCP server named probe once, then reply with the single word done."),
|
|
160
|
+
cwd,
|
|
161
|
+
mode: "full",
|
|
162
|
+
servers: [{ name: "probe", command: process.execPath, args: [script], env: {} }],
|
|
163
|
+
});
|
|
164
|
+
await turnEnded(side, started.session);
|
|
165
|
+
expect(existsSync(join(cwd, "probe.called"))).toBe(true);
|
|
166
|
+
} finally {
|
|
167
|
+
await side.dispose();
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
TURN_DEADLINE_MS * 2,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
test.skipIf(!live || !installed)(
|
|
174
|
+
"a real ZCode takes a deny-list at its start and does not offer the tool in it",
|
|
175
|
+
async () => {
|
|
176
|
+
const cwd = await tempDir("live-zcode-deny");
|
|
177
|
+
const script = join(cwd, "probe-server.ts");
|
|
178
|
+
await writeFile(script, PROBE_SERVER);
|
|
179
|
+
const side = control();
|
|
180
|
+
try {
|
|
181
|
+
const started = await side.start({
|
|
182
|
+
prompt: promptFromText("Call the tool niwa_probe of the MCP server named probe once if you have it, then reply with the single word done."),
|
|
183
|
+
cwd,
|
|
184
|
+
mode: "full",
|
|
185
|
+
servers: [{ name: "probe", command: process.execPath, args: [script], env: {} }],
|
|
186
|
+
visible: { actions: [], disabledTools: ["mcp__probe__niwa_probe"] },
|
|
187
|
+
});
|
|
188
|
+
await turnEnded(side, started.session);
|
|
189
|
+
expect(existsSync(join(cwd, "probe.called"))).toBe(false);
|
|
190
|
+
} finally {
|
|
191
|
+
await side.dispose();
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
TURN_DEADLINE_MS * 2,
|
|
195
|
+
);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// The mode ZCode restores a resumed session in: the last assistant message, then the project's
|
|
2
|
+
// `local_setting`, then the user's config file `permission.mode`, then the built-in `build`.
|
|
3
|
+
|
|
4
|
+
import { afterEach, beforeEach, expect, test } from "bun:test";
|
|
5
|
+
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { dirname, join } from "node:path";
|
|
7
|
+
|
|
8
|
+
import { Database } from "bun:sqlite";
|
|
9
|
+
|
|
10
|
+
import { tempDirSync } from "@niwa-labs/testing";
|
|
11
|
+
|
|
12
|
+
import { configuredModeOf } from "../src/config.ts";
|
|
13
|
+
import { assistant, createDatabase, user, writeSession } from "../src/fixtures.ts";
|
|
14
|
+
import { configPathOf, dbPathOf } from "../src/paths.ts";
|
|
15
|
+
import { persistedModeOf } from "../src/reading.ts";
|
|
16
|
+
|
|
17
|
+
let home: string;
|
|
18
|
+
let work: string;
|
|
19
|
+
let db: Database;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
home = tempDirSync("zcode-mode");
|
|
23
|
+
work = join(home, "work");
|
|
24
|
+
mkdirSync(work, { recursive: true });
|
|
25
|
+
mkdirSync(dirname(dbPathOf(home)), { recursive: true });
|
|
26
|
+
db = createDatabase(dbPathOf(home));
|
|
27
|
+
writeSession(db, "sess_plain", [user("m1", "hi"), assistant("m2", "hello")], { directory: work, project: "proj" });
|
|
28
|
+
});
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
db.close();
|
|
31
|
+
rmSync(home, { recursive: true, force: true });
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const writeConfig = (content: unknown): void => {
|
|
35
|
+
writeFileSync(configPathOf(home), typeof content === "string" ? content : JSON.stringify(content));
|
|
36
|
+
};
|
|
37
|
+
const setProjectMode = (mode: string): void => {
|
|
38
|
+
db.query("insert into local_setting values ('project', 'proj', 'permission', 'mode', ?, 1, 1, 1)").run(JSON.stringify({ mode }));
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
test("with no config file the built-in mode is the answer", () => {
|
|
42
|
+
expect(configuredModeOf(home)).toBeUndefined();
|
|
43
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("build");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("the user's config file mode stands in for the built-in one", () => {
|
|
47
|
+
writeConfig({ permission: { mode: "yolo", allowedTools: ["Read"] }, ui: { locale: "en" } });
|
|
48
|
+
expect(configuredModeOf(home)).toBe("yolo");
|
|
49
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("yolo");
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("a config file that names no mode leaves the built-in one", () => {
|
|
53
|
+
writeConfig({ permission: { allowedTools: ["Read"] } });
|
|
54
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("build");
|
|
55
|
+
writeConfig({});
|
|
56
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("build");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("the project's local setting wins over the config file", () => {
|
|
60
|
+
writeConfig({ permission: { mode: "yolo" } });
|
|
61
|
+
setProjectMode("plan");
|
|
62
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("plan");
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("a mode stamped on the last assistant message wins over both", () => {
|
|
66
|
+
writeConfig({ permission: { mode: "yolo" } });
|
|
67
|
+
setProjectMode("plan");
|
|
68
|
+
const stamped = assistant("m4", "done");
|
|
69
|
+
writeSession(db, "sess_stamped", [user("m3", "hi"), { ...stamped, data: { ...stamped.data, mode: "edit" } }], { directory: work, project: "proj" });
|
|
70
|
+
expect(persistedModeOf(home, "sess_stamped")).toBe("edit");
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
test("a project's config files cannot set the mode: ZCode strips permission from them", () => {
|
|
74
|
+
writeFileSync(join(work, "zcode.json"), JSON.stringify({ permission: { mode: "plan" } }));
|
|
75
|
+
mkdirSync(join(work, ".zcode"));
|
|
76
|
+
writeFileSync(join(work, ".zcode", "config.json"), JSON.stringify({ permission: { mode: "guarded" } }));
|
|
77
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("build");
|
|
78
|
+
writeConfig({ permission: { mode: "auto" } });
|
|
79
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("auto");
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("a config file ZCode would not load is ignored: bad JSON, not an object, a mode it does not know", () => {
|
|
83
|
+
for (const content of ["{ not json", "[]", '"yolo"', { permission: { mode: "reckless" } }, { permission: { mode: "" } }, { permission: "yolo" }]) {
|
|
84
|
+
writeConfig(content);
|
|
85
|
+
expect(configuredModeOf(home)).toBeUndefined();
|
|
86
|
+
expect(persistedModeOf(home, "sess_plain")).toBe("build");
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test("every mode ZCode's schema accepts is read", () => {
|
|
91
|
+
for (const mode of ["plan", "build", "edit", "yolo", "guarded", "auto"]) {
|
|
92
|
+
writeConfig({ permission: { mode } });
|
|
93
|
+
expect(configuredModeOf(home)).toBe(mode);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test("a session the database does not know is unreadable whatever the config says", () => {
|
|
98
|
+
writeConfig({ permission: { mode: "yolo" } });
|
|
99
|
+
expect(persistedModeOf(home, "sess_nowhere")).toBeUndefined();
|
|
100
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// The profile of a ZCode installation.
|
|
2
|
+
//
|
|
3
|
+
// Its program, the runtime it runs on and its home. It stays admitted: a ZCode session listens on a
|
|
4
|
+
// unix socket it makes in its temp directory, which a box closed to reading does not let it bind,
|
|
5
|
+
// so no session has run in one with this profile alone.
|
|
6
|
+
|
|
7
|
+
import { expect, test } from "bun:test";
|
|
8
|
+
|
|
9
|
+
import { resolveProfile } from "@niwa-labs/sandbox";
|
|
10
|
+
|
|
11
|
+
import { zcodeKind } from "../src/index.ts";
|
|
12
|
+
|
|
13
|
+
test("an installation's profile is its program, the runtime it runs on and its home, with the hosts the owner names", () => {
|
|
14
|
+
const binding = zcodeKind.bind({ id: "zcode-a", home: "/srv/zcode", control: { binary: "/bin/sh" }, net: ["api.z.ai"] });
|
|
15
|
+
const profile = resolveProfile(binding.profile ?? {}, "zcode-a", { home: "/home/u", env: { PATH: "/nowhere" } });
|
|
16
|
+
expect(profile.read).toEqual(["/bin/sh"]);
|
|
17
|
+
expect(profile.write).toEqual(["/srv/zcode"]);
|
|
18
|
+
expect(profile.net).toEqual(["api.z.ai"]);
|
|
19
|
+
expect(zcodeKind.profile.status).toBe("admitted");
|
|
20
|
+
});
|