mixdog 0.9.152 → 0.9.154
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/LICENSES/browser-import-NOTICE.txt +11 -0
- package/NOTICE.md +11 -0
- package/README.md +8 -10
- package/package.json +19 -3
- package/scripts/computer-task-cost-report.mjs +144 -0
- package/scripts/run-office-live-tests.mjs +32 -0
- package/src/agents/front-worker/AGENT.md +13 -0
- package/src/agents/front-worker/agent.json +6 -0
- package/src/agents/heavy-worker/AGENT.md +10 -11
- package/src/agents/heavy-worker/agent.json +1 -1
- package/src/agents/maintainer/AGENT.md +0 -2
- package/src/agents/reviewer/AGENT.md +9 -13
- package/src/agents/reviewer/agent.json +1 -1
- package/src/agents/security/AGENT.md +14 -0
- package/src/agents/security/agent.json +6 -0
- package/src/agents/worker/AGENT.md +8 -8
- package/src/agents/worker/agent.json +1 -1
- package/src/agents/writer/AGENT.md +14 -0
- package/src/agents/writer/agent.json +6 -0
- package/src/rules/agent/00-common.md +4 -7
- package/src/rules/lead/01-general.md +0 -3
- package/src/rules/shared/10-tool-workflow.md +10 -2
- package/src/rules/shared/60-verification.md +2 -0
- package/src/runtime/agent/orchestrator/agent-runtime/agent-dispatch.mjs +183 -26
- package/src/runtime/agent/orchestrator/agent-runtime/session-builder.mjs +4 -0
- package/src/runtime/agent/orchestrator/cache-break-trace.mjs +109 -0
- package/src/runtime/agent/orchestrator/config.mjs +7 -2
- package/src/runtime/agent/orchestrator/providers/admission-scheduler.mjs +16 -3
- package/src/runtime/agent/orchestrator/providers/lib/anthropic-request-utils.mjs +9 -1
- package/src/runtime/agent/orchestrator/providers/media-normalization.mjs +30 -9
- package/src/runtime/agent/orchestrator/providers/openai-codex-metadata.mjs +18 -26
- package/src/runtime/agent/orchestrator/providers/openai-oauth-http-sse.mjs +25 -2
- package/src/runtime/agent/orchestrator/providers/openai-oauth-ws.mjs +103 -10
- package/src/runtime/agent/orchestrator/providers/openai-turn-state.mjs +68 -0
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta.mjs +36 -11
- package/src/runtime/agent/orchestrator/providers/openai-ws-pool.mjs +140 -86
- package/src/runtime/agent/orchestrator/providers/openai-ws-stream.mjs +9 -13
- package/src/runtime/agent/orchestrator/session/agent-loop.mjs +72 -4
- package/src/runtime/agent/orchestrator/session/browser-snapshot-supersession.mjs +61 -0
- package/src/runtime/agent/orchestrator/session/compact/handoff.mjs +0 -22
- package/src/runtime/agent/orchestrator/session/compact/messages.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/compact/runner.mjs +11 -23
- package/src/runtime/agent/orchestrator/session/compact/summary.mjs +28 -269
- package/src/runtime/agent/orchestrator/session/compact.mjs +0 -6
- package/src/runtime/agent/orchestrator/session/context-utils.mjs +86 -11
- package/src/runtime/agent/orchestrator/session/eager-dispatch.mjs +17 -1
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.mjs +12 -8
- package/src/runtime/agent/orchestrator/session/loop/compact-policy.mjs +110 -2
- package/src/runtime/agent/orchestrator/session/loop/pre-dispatch-deny.mjs +3 -16
- package/src/runtime/agent/orchestrator/session/loop/recall-fasttrack.mjs +80 -18
- package/src/runtime/agent/orchestrator/session/loop/steering.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-exec.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/loop/tool-helpers.mjs +6 -0
- package/src/runtime/agent/orchestrator/session/manager/ask-session.mjs +80 -21
- package/src/runtime/agent/orchestrator/session/manager/compaction-runner.mjs +33 -72
- package/src/runtime/agent/orchestrator/session/manager/session-crud.mjs +21 -2
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.mjs +25 -51
- package/src/runtime/agent/orchestrator/session/manager/status-telemetry.mjs +3 -0
- package/src/runtime/agent/orchestrator/session/manager/tool-resolution.mjs +4 -110
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.mjs +39 -15
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint.mjs +14 -4
- package/src/runtime/agent/orchestrator/session/pre-send-compact.mjs +41 -8
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.mjs +129 -12
- package/src/runtime/agent/orchestrator/session/send-with-recovery.mjs +2 -2
- package/src/runtime/agent/orchestrator/session/store/listing.mjs +8 -1
- package/src/runtime/agent/orchestrator/session/store/save-worker.mjs +15 -1
- package/src/runtime/agent/orchestrator/session/store-summary-index.mjs +36 -2
- package/src/runtime/agent/orchestrator/session/store-summary-reader.mjs +157 -30
- package/src/runtime/agent/orchestrator/session/store-summary-visibility.mjs +57 -0
- package/src/runtime/agent/orchestrator/session/store.mjs +3 -1
- package/src/runtime/agent/orchestrator/session/tool-batch.mjs +22 -0
- package/src/runtime/agent/orchestrator/tools/builtin/read-special-files.mjs +6 -6
- package/src/runtime/agent/orchestrator/tools/progress-message.mjs +4 -0
- package/src/runtime/attachments/pdf-extract.mjs +3 -0
- package/src/runtime/attachments/pdfjs-runtime.mjs +13 -0
- package/src/runtime/browser-bridge/action-schema.mjs +251 -0
- package/src/runtime/browser-bridge/client.mjs +75 -26
- package/src/runtime/browser-bridge/tool-defs.mjs +132 -15
- package/src/runtime/computer-bridge/action-schema.mjs +653 -0
- package/src/runtime/computer-bridge/client.mjs +211 -28
- package/src/runtime/computer-bridge/tool-defs.mjs +25 -45
- package/src/runtime/office/assurance-benchmark.mjs +358 -0
- package/src/runtime/office/assurance.mjs +833 -0
- package/src/runtime/office/benchmark.mjs +496 -0
- package/src/runtime/office/capabilities.mjs +551 -0
- package/src/runtime/office/com-adapter.mjs +283 -0
- package/src/runtime/office/content-model.mjs +183 -0
- package/src/runtime/office/contract-benchmark.mjs +105 -0
- package/src/runtime/office/design-library.mjs +1562 -0
- package/src/runtime/office/design-system.mjs +1966 -0
- package/src/runtime/office/index.mjs +2413 -0
- package/src/runtime/office/journal.mjs +82 -0
- package/src/runtime/office/office-com-host.ps1 +3781 -0
- package/src/runtime/office/office-com-session-host.ps1 +855 -0
- package/src/runtime/office/ooxml-validator.mjs +271 -0
- package/src/runtime/office/pagination.mjs +132 -0
- package/src/runtime/office/pdf-adapter.mjs +591 -0
- package/src/runtime/office/pdf-analysis.mjs +372 -0
- package/src/runtime/office/pdf-render.mjs +167 -0
- package/src/runtime/office/pdf-security.mjs +63 -0
- package/src/runtime/office/polish-benchmark.mjs +190 -0
- package/src/runtime/office/portable-ooxml.mjs +1867 -0
- package/src/runtime/office/quality-live-benchmark.mjs +486 -0
- package/src/runtime/office/quality-pipeline.mjs +136 -0
- package/src/runtime/office/tabular.mjs +302 -0
- package/src/runtime/office/templates/mixdog-executive.pptx +0 -0
- package/src/runtime/office/templates/mixdog-executive.pptx.mixdog.json +190 -0
- package/src/runtime/office/tool-defs.mjs +113 -0
- package/src/runtime/office/visual-diff.mjs +89 -0
- package/src/runtime/office/xlsx-assertions.mjs +172 -0
- package/src/runtime/office/xlsx-contract.mjs +147 -0
- package/src/runtime/shared/agent-route-config.mjs +9 -0
- package/src/runtime/shared/tool-execution-contract.mjs +16 -0
- package/src/runtime/shared/tool-surface.mjs +9 -0
- package/src/session-runtime/context-status.mjs +9 -3
- package/src/session-runtime/deferred-tool-delta.mjs +104 -0
- package/src/session-runtime/goal-runtime.mjs +617 -197
- package/src/session-runtime/lifecycle-api.mjs +50 -8
- package/src/session-runtime/provider-request-snapshot.mjs +33 -9
- package/src/session-runtime/resource-api.mjs +31 -94
- package/src/session-runtime/runtime-core.mjs +78 -26
- package/src/session-runtime/session-lifecycle.mjs +34 -12
- package/src/session-runtime/session-title.mjs +2 -2
- package/src/session-runtime/session-turn-api.mjs +15 -14
- package/src/session-runtime/tool-catalog-data.mjs +1 -1
- package/src/session-runtime/tool-catalog.mjs +38 -99
- package/src/session-runtime/tool-defs.mjs +6 -1
- package/src/session-runtime/tool-surface.mjs +18 -8
- package/src/session-runtime/workflow-agents-api.mjs +8 -25
- package/src/session-runtime/workflow.mjs +8 -6
- package/src/standalone/agent-tool/helpers.mjs +2 -2
- package/src/standalone/agent-tool/job-views.mjs +3 -1
- package/src/standalone/agent-tool/notify.mjs +5 -1
- package/src/standalone/agent-tool/render.mjs +3 -0
- package/src/standalone/agent-tool/spawn-flow.mjs +61 -16
- package/src/standalone/agent-tool/tool-def.mjs +1 -1
- package/src/standalone/agent-tool/worker-index.mjs +123 -0
- package/src/standalone/agent-tool/worker-rows.mjs +2 -1
- package/src/standalone/agent-tool.mjs +57 -10
- package/src/standalone/daemon.mjs +105 -6
- package/src/standalone/session-runtime-host.mjs +61 -48
- package/src/standalone/session-runtime-inline-host.mjs +34 -127
- package/src/standalone/session-runtime-worker.mjs +20 -198
- package/src/standalone/session-service.mjs +632 -7
- package/src/tui/dist/index.mjs +24 -1
- package/src/tui/lib/voice-setup.mjs +4 -1
- package/src/tui/session/context-state.mjs +2 -13
- package/src/tui/session/goal-continuation.mjs +38 -7
- package/src/tui/session/session-api-ext.mjs +9 -0
- package/src/tui/session/session-api.mjs +15 -1
- package/src/tui/session/session-flow.mjs +25 -1
- package/src/tui/session/turn.mjs +88 -16
- package/src/tui/session-local.mjs +25 -3
- package/src/vendor/statusline/src/gateway/route-meta.mjs +31 -0
- package/scripts/generate-voice-runtime-manifest.test.mjs +0 -135
- package/scripts/native-binary-arch.test.mjs +0 -111
- package/scripts/patch-replay.test.mjs +0 -94
- package/src/headless-exec.test.mjs +0 -539
- package/src/runtime/agent/orchestrator/agent-trace-timing.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/context/collect-skills.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/mcp/cancellation.test.mjs +0 -139
- package/src/runtime/agent/orchestrator/mcp/features.test.mjs +0 -66
- package/src/runtime/agent/orchestrator/mcp/security.test.mjs +0 -80
- package/src/runtime/agent/orchestrator/providers/anthropic-fast-mode.test.mjs +0 -90
- package/src/runtime/agent/orchestrator/providers/anthropic-server-fallback.test.mjs +0 -215
- package/src/runtime/agent/orchestrator/providers/antigravity-oauth.test.mjs +0 -165
- package/src/runtime/agent/orchestrator/providers/media-parity.test.mjs +0 -142
- package/src/runtime/agent/orchestrator/providers/openai-codex-identity.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/providers/openai-codex-model.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/providers/openai-ws-delta-parity.test.mjs +0 -190
- package/src/runtime/agent/orchestrator/providers/provider-replay.test.mjs +0 -235
- package/src/runtime/agent/orchestrator/providers/sse-framing.test.mjs +0 -719
- package/src/runtime/agent/orchestrator/session/cache/prefetch-cache.test.mjs +0 -40
- package/src/runtime/agent/orchestrator/session/compact-policy.test.mjs +0 -176
- package/src/runtime/agent/orchestrator/session/compaction-read-reset.test.mjs +0 -161
- package/src/runtime/agent/orchestrator/session/eager-dispatch.test.mjs +0 -115
- package/src/runtime/agent/orchestrator/session/evidence-union.test.mjs +0 -228
- package/src/runtime/agent/orchestrator/session/image-strip-recovery.test.mjs +0 -245
- package/src/runtime/agent/orchestrator/session/lossless-tool-output.test.mjs +0 -125
- package/src/runtime/agent/orchestrator/session/manager/pending-messages-persistence.test.mjs +0 -325
- package/src/runtime/agent/orchestrator/session/manager/session-lifecycle.test.mjs +0 -70
- package/src/runtime/agent/orchestrator/session/manager/turn-checkpoint-journal.test.mjs +0 -457
- package/src/runtime/agent/orchestrator/session/provider-prefix-guard.test.mjs +0 -117
- package/src/runtime/agent/orchestrator/session/reduction-metrics.test.mjs +0 -87
- package/src/runtime/agent/orchestrator/session/store/serialize.test.mjs +0 -60
- package/src/runtime/agent/orchestrator/session/store-summary-reader.test.mjs +0 -583
- package/src/runtime/agent/orchestrator/session/task-wait-control.test.mjs +0 -78
- package/src/runtime/agent/orchestrator/tools/builtin/absence-absorption.test.mjs +0 -43
- package/src/runtime/agent/orchestrator/tools/builtin/absolute-glob-expand.test.mjs +0 -63
- package/src/runtime/agent/orchestrator/tools/builtin/bash-tool-cwd-env.test.mjs +0 -14
- package/src/runtime/agent/orchestrator/tools/builtin/edit-encoding-eol.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/edit-sequential-occupation.test.mjs +0 -224
- package/src/runtime/agent/orchestrator/tools/builtin/enoent-outside-project.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/find-search-budget.test.mjs +0 -103
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-policy.test.mjs +0 -30
- package/src/runtime/agent/orchestrator/tools/builtin/git-command-tool.test.mjs +0 -390
- package/src/runtime/agent/orchestrator/tools/builtin/git-repo-rw-lock.test.mjs +0 -83
- package/src/runtime/agent/orchestrator/tools/builtin/grep-output-budget.test.mjs +0 -31
- package/src/runtime/agent/orchestrator/tools/builtin/grep-single-file-rescue.test.mjs +0 -106
- package/src/runtime/agent/orchestrator/tools/builtin/lib/shell-job-records.test.mjs +0 -102
- package/src/runtime/agent/orchestrator/tools/builtin/list-tool-integrity.test.mjs +0 -152
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-health.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/native-search-transport.test.mjs +0 -24
- package/src/runtime/agent/orchestrator/tools/builtin/noise-dir-visibility.test.mjs +0 -69
- package/src/runtime/agent/orchestrator/tools/builtin/read-glob-survey.test.mjs +0 -71
- package/src/runtime/agent/orchestrator/tools/builtin/runtime-capabilities.test.mjs +0 -56
- package/src/runtime/agent/orchestrator/tools/builtin/search-builders.test.mjs +0 -16
- package/src/runtime/agent/orchestrator/tools/builtin/search-glob-top-k.test.mjs +0 -39
- package/src/runtime/agent/orchestrator/tools/builtin/write-symlink.test.mjs +0 -153
- package/src/runtime/agent/orchestrator/tools/code-graph/aggregate-anchor-relocation.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/dispatch.test.mjs +0 -88
- package/src/runtime/agent/orchestrator/tools/code-graph/loose-file-target.test.mjs +0 -72
- package/src/runtime/agent/orchestrator/tools/code-graph/memory-cache.test.mjs +0 -54
- package/src/runtime/agent/orchestrator/tools/code-graph/search-references.test.mjs +0 -20
- package/src/runtime/agent/orchestrator/tools/code-graph/symbol-search-scope.test.mjs +0 -55
- package/src/runtime/agent/orchestrator/tools/code-graph/text-span-mask.test.mjs +0 -268
- package/src/runtime/agent/orchestrator/tools/env-scrub.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/graph-binary-fetcher.test.mjs +0 -19
- package/src/runtime/agent/orchestrator/tools/lib/native-spawn-client.test.mjs +0 -104
- package/src/runtime/agent/orchestrator/tools/patch/engine-contract-gate.test.mjs +0 -661
- package/src/runtime/agent/orchestrator/tools/patch/patch-codec-eol.test.mjs +0 -552
- package/src/runtime/agent/orchestrator/tools/patch/patch-symlink.test.mjs +0 -141
- package/src/runtime/agent/orchestrator/tools/patch/v4a-pure-move.test.mjs +0 -57
- package/src/runtime/agent/orchestrator/tools/patch/v4a-section-coalesce.test.mjs +0 -81
- package/src/runtime/agent/orchestrator/tools/spawn-binary-fetcher.test.mjs +0 -52
- package/src/runtime/attachments/store.test.mjs +0 -209
- package/src/runtime/channels/lib/voice-runtime-fetcher.test.mjs +0 -17
- package/src/runtime/channels/lib/webhook/deliveries.test.mjs +0 -18
- package/src/runtime/channels/lib/webhook/relay-tunnel.test.mjs +0 -68
- package/src/runtime/media/adapters/codex-image.test.mjs +0 -22
- package/src/runtime/media/download.test.mjs +0 -52
- package/src/runtime/media/renditions.test.mjs +0 -99
- package/src/runtime/media/store.test.mjs +0 -159
- package/src/runtime/memory/lib/archive-security.test.mjs +0 -128
- package/src/runtime/memory/lib/embedding-model-config.test.mjs +0 -33
- package/src/runtime/memory/lib/http-wire.test.mjs +0 -15
- package/src/runtime/memory/lib/memory-cycle-packets.test.mjs +0 -49
- package/src/runtime/memory/lib/memory-cycle2-shared.test.mjs +0 -78
- package/src/runtime/memory/lib/memory-embedding-migration.test.mjs +0 -50
- package/src/runtime/memory/lib/pg/process.test.mjs +0 -36
- package/src/runtime/memory/lib/trace-store.test.mjs +0 -57
- package/src/runtime/memory/lib/transcript-ingest.test.mjs +0 -52
- package/src/runtime/shared/background-tasks.test.mjs +0 -78
- package/src/runtime/shared/bounded-download.test.mjs +0 -41
- package/src/runtime/shared/channel-notification-routing.test.mjs +0 -25
- package/src/runtime/shared/child-spawn-remote.test.mjs +0 -124
- package/src/runtime/shared/remote-intent.test.mjs +0 -40
- package/src/runtime/shared/resource-admission.test.mjs +0 -43
- package/src/runtime/shared/runtime-root.test.mjs +0 -34
- package/src/runtime/shared/schedule-time.test.mjs +0 -29
- package/src/runtime/shared/session-runtime-health.test.mjs +0 -83
- package/src/runtime/shared/skill-document.test.mjs +0 -81
- package/src/runtime/shared/tool-surface.test.mjs +0 -87
- package/src/runtime/shared/update-checker.test.mjs +0 -33
- package/src/runtime/shared/user-cwd.test.mjs +0 -43
- package/src/runtime/shared/webhook-session-run.test.mjs +0 -14
- package/src/session-runtime/agent-disable.test.mjs +0 -123
- package/src/session-runtime/cwd-plugins.test.mjs +0 -75
- package/src/session-runtime/cwd-tool-routing.test.mjs +0 -61
- package/src/session-runtime/global-extensions.test.mjs +0 -28
- package/src/session-runtime/goal-runtime.test.mjs +0 -108
- package/src/session-runtime/lifecycle-api.test.mjs +0 -21
- package/src/session-runtime/model-settings-persist.test.mjs +0 -105
- package/src/session-runtime/notification-bus.test.mjs +0 -148
- package/src/session-runtime/plugin-mcp-standard.test.mjs +0 -177
- package/src/session-runtime/prewarm.test.mjs +0 -52
- package/src/session-runtime/provider-request-snapshot.test.mjs +0 -37
- package/src/session-runtime/resource-api-global.test.mjs +0 -69
- package/src/session-runtime/session-lifecycle.test.mjs +0 -125
- package/src/session-runtime/session-title.test.mjs +0 -36
- package/src/session-runtime/skills-api.test.mjs +0 -99
- package/src/session-runtime/tool-policy-surface.test.mjs +0 -331
- package/src/standalone/agent-tool/helpers.test.mjs +0 -62
- package/src/standalone/agent-tool/notify.test.mjs +0 -37
- package/src/standalone/agent-tool/spawn-flow.test.mjs +0 -63
- package/src/standalone/channel-restart.test.mjs +0 -145
- package/src/standalone/channel-session-router.test.mjs +0 -37
- package/src/standalone/channel-worker-heartbeat.test.mjs +0 -30
- package/src/standalone/hook-bus/handlers.test.mjs +0 -88
- package/src/standalone/plugin-admin.test.mjs +0 -173
- package/src/standalone/session-runtime-agent-control-client.test.mjs +0 -71
- package/src/standalone/session-runtime-dispatch-cancel.test.mjs +0 -139
- package/src/standalone/session-runtime-host-factory.test.mjs +0 -31
- package/src/standalone/session-runtime-host-health.test.mjs +0 -160
- package/src/standalone/session-runtime-inline-host.test.mjs +0 -83
- package/src/standalone/session-runtime-provider-cooldown.test.mjs +0 -80
- package/src/standalone/session-runtime-shard-host.test.mjs +0 -569
- package/src/standalone/session-runtime-shard-router.test.mjs +0 -101
- package/src/tui/app/live-spinner-visibility.test.mjs +0 -44
- package/src/tui/app/panel-epoch.test.mjs +0 -1009
- package/src/tui/app/panel-handoff.test.mjs +0 -311
- package/src/tui/app/prompt-submit.test.mjs +0 -206
- package/src/tui/session/completion-card-restore.test.mjs +0 -111
- package/src/tui/session/goal-continuation.test.mjs +0 -84
- package/src/tui/session/oauth-flows.test.mjs +0 -134
- package/src/tui/session/queue-helpers.test.mjs +0 -46
- package/src/tui/session/session-action-surface.test.mjs +0 -108
- package/src/tui/session/task-wait-submit.test.mjs +0 -80
- package/src/tui/session/tool-result-status.test.mjs +0 -131
- package/src/tui/session/tui-steering-persist.test.mjs +0 -104
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import test from 'node:test';
|
|
6
|
-
import { createChannelTransport } from './channel-transport.mjs';
|
|
7
|
-
|
|
8
|
-
async function post(endpoint, path, body) {
|
|
9
|
-
const response = await fetch(`http://127.0.0.1:${endpoint.port}${path}`, {
|
|
10
|
-
method: 'POST',
|
|
11
|
-
headers: {
|
|
12
|
-
'content-type': 'application/json',
|
|
13
|
-
'x-mixdog-daemon-token': endpoint.token,
|
|
14
|
-
},
|
|
15
|
-
body: JSON.stringify(body),
|
|
16
|
-
});
|
|
17
|
-
const value = await response.json();
|
|
18
|
-
if (!response.ok) throw new Error(value?.error || `HTTP ${response.status}`);
|
|
19
|
-
return value;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function writeIntent(path, {
|
|
23
|
-
sessionId = 'session_restart',
|
|
24
|
-
cwd = process.cwd(),
|
|
25
|
-
} = {}) {
|
|
26
|
-
const transcriptPath = join(tmpdir(), `${sessionId}.jsonl`);
|
|
27
|
-
writeFileSync(path, JSON.stringify({
|
|
28
|
-
version: 1,
|
|
29
|
-
sessionId,
|
|
30
|
-
transcriptPath,
|
|
31
|
-
cwd,
|
|
32
|
-
updatedAt: Date.now(),
|
|
33
|
-
}));
|
|
34
|
-
return transcriptPath;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
test('daemon boot restores the pinned session without a registered client', async () => {
|
|
38
|
-
const dir = mkdtempSync(join(tmpdir(), 'mixdog-channel-restart-'));
|
|
39
|
-
const intentPath = join(dir, 'channel-remote-intent.json');
|
|
40
|
-
const statePath = join(dir, 'channel-remote-state.json');
|
|
41
|
-
const transcriptPath = writeIntent(intentPath);
|
|
42
|
-
const calls = [];
|
|
43
|
-
let transport;
|
|
44
|
-
transport = createChannelTransport({
|
|
45
|
-
remoteIntentPath: intentPath,
|
|
46
|
-
remoteStatePath: statePath,
|
|
47
|
-
handleCall: async (name, args) => {
|
|
48
|
-
calls.push({ name, args });
|
|
49
|
-
return { ok: true };
|
|
50
|
-
},
|
|
51
|
-
});
|
|
52
|
-
await transport.start();
|
|
53
|
-
try {
|
|
54
|
-
assert.equal(transport.remoteIntentSessionId, 'session_restart');
|
|
55
|
-
assert.equal(transport.remoteSessionId, null);
|
|
56
|
-
assert.equal(await transport.restoreRemoteIntent(), true);
|
|
57
|
-
assert.deepEqual(calls[0], {
|
|
58
|
-
name: 'activate_channel_bridge',
|
|
59
|
-
args: {
|
|
60
|
-
active: true,
|
|
61
|
-
sessionId: 'session_restart',
|
|
62
|
-
transcriptPath,
|
|
63
|
-
restore: true,
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
assert.equal(transport.remoteSessionId, 'session_restart');
|
|
67
|
-
assert.equal(Object.hasOwn(JSON.parse(readFileSync(intentPath, 'utf8')), 'ownerLeadPid'), false);
|
|
68
|
-
assert.equal(JSON.parse(readFileSync(statePath, 'utf8')).enabled, true);
|
|
69
|
-
} finally {
|
|
70
|
-
await transport.stop();
|
|
71
|
-
rmSync(dir, { recursive: true, force: true });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('client registration cannot select or replace the pinned session', async () => {
|
|
76
|
-
const dir = mkdtempSync(join(tmpdir(), 'mixdog-channel-session-pin-'));
|
|
77
|
-
const intentPath = join(dir, 'channel-remote-intent.json');
|
|
78
|
-
writeIntent(intentPath);
|
|
79
|
-
const calls = [];
|
|
80
|
-
const transport = createChannelTransport({
|
|
81
|
-
remoteIntentPath: intentPath,
|
|
82
|
-
handleCall: async (name, args) => {
|
|
83
|
-
calls.push({ name, args });
|
|
84
|
-
return { ok: true };
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
const endpoint = await transport.start();
|
|
88
|
-
try {
|
|
89
|
-
assert.equal(await transport.restoreRemoteIntent(), true);
|
|
90
|
-
await post(endpoint, '/client/register', {
|
|
91
|
-
leadPid: process.pid,
|
|
92
|
-
cwd: join(process.cwd(), 'other'),
|
|
93
|
-
passive: true,
|
|
94
|
-
restoreSessionId: 'session_other',
|
|
95
|
-
});
|
|
96
|
-
assert.equal(calls.length, 1);
|
|
97
|
-
assert.equal(transport.remoteSessionId, 'session_restart');
|
|
98
|
-
assert.equal(transport._pointerTokenForTest, null);
|
|
99
|
-
} finally {
|
|
100
|
-
await transport.stop();
|
|
101
|
-
rmSync(dir, { recursive: true, force: true });
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('daemon replacement drain preserves the session intent without deactivating it', async () => {
|
|
106
|
-
const dir = mkdtempSync(join(tmpdir(), 'mixdog-channel-drain-'));
|
|
107
|
-
const intentPath = join(dir, 'channel-remote-intent.json');
|
|
108
|
-
const transcriptPath = join(dir, 'session_drain.jsonl');
|
|
109
|
-
const calls = [];
|
|
110
|
-
let transport;
|
|
111
|
-
transport = createChannelTransport({
|
|
112
|
-
remoteIntentPath: intentPath,
|
|
113
|
-
handleCall: async (name, args) => {
|
|
114
|
-
calls.push({ name, args });
|
|
115
|
-
if (name === 'activate_channel_bridge' && args.active === true) {
|
|
116
|
-
transport.notify('notifications/mixdog/remote', { state: 'acquired' });
|
|
117
|
-
}
|
|
118
|
-
return { ok: true };
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
const endpoint = await transport.start();
|
|
122
|
-
try {
|
|
123
|
-
const registered = await post(endpoint, '/client/register', {
|
|
124
|
-
leadPid: process.pid,
|
|
125
|
-
cwd: process.cwd(),
|
|
126
|
-
passive: true,
|
|
127
|
-
restoreSessionId: 'session_drain',
|
|
128
|
-
});
|
|
129
|
-
await post(endpoint, '/call', {
|
|
130
|
-
token: registered.token,
|
|
131
|
-
name: 'activate_channel_bridge',
|
|
132
|
-
args: {
|
|
133
|
-
active: true,
|
|
134
|
-
sessionId: 'session_drain',
|
|
135
|
-
transcriptPath,
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
assert.equal(transport.beginDrain('daemon replacement'), true);
|
|
139
|
-
assert.equal(JSON.parse(readFileSync(intentPath, 'utf8')).sessionId, 'session_drain');
|
|
140
|
-
assert.equal(calls.filter((call) => call.args?.active === false).length, 0);
|
|
141
|
-
} finally {
|
|
142
|
-
await transport.stop();
|
|
143
|
-
rmSync(dir, { recursive: true, force: true });
|
|
144
|
-
}
|
|
145
|
-
});
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import test from 'node:test';
|
|
3
|
-
|
|
4
|
-
import { createChannelSessionRouter } from './channel-session-router.mjs';
|
|
5
|
-
|
|
6
|
-
test('channel inbound submits directly to its pinned session without a UI client', async () => {
|
|
7
|
-
const calls = [];
|
|
8
|
-
const route = createChannelSessionRouter({
|
|
9
|
-
getSessionId: () => 'sess_linked',
|
|
10
|
-
getSessionService: () => ({
|
|
11
|
-
async submitSession(args) {
|
|
12
|
-
calls.push(args);
|
|
13
|
-
},
|
|
14
|
-
}),
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
assert.equal(route('notifications/claude/channel', {
|
|
18
|
-
content: 'discord inbound',
|
|
19
|
-
meta: { instruction: 'answer discord inbound' },
|
|
20
|
-
}), true);
|
|
21
|
-
await new Promise((resolve) => setImmediate(resolve));
|
|
22
|
-
assert.deepEqual(calls, [{
|
|
23
|
-
sessionId: 'sess_linked',
|
|
24
|
-
prompt: 'answer discord inbound',
|
|
25
|
-
options: { source: 'channel' },
|
|
26
|
-
}]);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
test('channel router consumes only channel inbound notifications', () => {
|
|
30
|
-
let calls = 0;
|
|
31
|
-
const route = createChannelSessionRouter({
|
|
32
|
-
getSessionId: () => 'sess_linked',
|
|
33
|
-
getSessionService: () => ({ submitSession() { calls += 1; } }),
|
|
34
|
-
});
|
|
35
|
-
assert.equal(route('notifications/mixdog/remote', { state: 'acquired' }), false);
|
|
36
|
-
assert.equal(calls, 0);
|
|
37
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { existsSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
3
|
-
import { tmpdir } from 'node:os';
|
|
4
|
-
import { join } from 'node:path';
|
|
5
|
-
import test from 'node:test';
|
|
6
|
-
|
|
7
|
-
import { pruneStaleChannelClientHeartbeats } from './channel-worker.mjs';
|
|
8
|
-
|
|
9
|
-
test('channel heartbeat sweep removes dead and expired rows only', () => {
|
|
10
|
-
const root = mkdtempSync(join(tmpdir(), 'mixdog-channel-heartbeat-test-'));
|
|
11
|
-
const now = 100_000;
|
|
12
|
-
try {
|
|
13
|
-
writeFileSync(join(root, '1.json'), JSON.stringify({ pid: 1, updatedAt: now - 1_000 }));
|
|
14
|
-
writeFileSync(join(root, '2.json'), JSON.stringify({ pid: 2, updatedAt: now - 60_000 }));
|
|
15
|
-
writeFileSync(join(root, '3.json'), JSON.stringify({ pid: 3, updatedAt: now - 1_000 }));
|
|
16
|
-
|
|
17
|
-
const removed = pruneStaleChannelClientHeartbeats(root, {
|
|
18
|
-
now,
|
|
19
|
-
maxAgeMs: 30_000,
|
|
20
|
-
pidAlive: (pid) => pid !== 3,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
assert.equal(removed, 2);
|
|
24
|
-
assert.equal(existsSync(join(root, '1.json')), true);
|
|
25
|
-
assert.equal(existsSync(join(root, '2.json')), false);
|
|
26
|
-
assert.equal(existsSync(join(root, '3.json')), false);
|
|
27
|
-
} finally {
|
|
28
|
-
rmSync(root, { recursive: true, force: true });
|
|
29
|
-
}
|
|
30
|
-
});
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
2
|
-
import assert from 'node:assert/strict';
|
|
3
|
-
import dns from 'node:dns';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
MAX_HTTP_HOOK_RESPONSE_BYTES,
|
|
7
|
-
runHttpHandler,
|
|
8
|
-
} from './handlers.mjs';
|
|
9
|
-
|
|
10
|
-
test('public HTTP hooks use the DNS-pinned fetch lane', async () => {
|
|
11
|
-
let publicCalls = 0;
|
|
12
|
-
let privateCalls = 0;
|
|
13
|
-
const result = await runHttpHandler(
|
|
14
|
-
{ type: 'http', url: 'https://example.com/hook' },
|
|
15
|
-
{ ok: true },
|
|
16
|
-
'Stop',
|
|
17
|
-
{
|
|
18
|
-
publicFetch: async (_url, options) => {
|
|
19
|
-
publicCalls += 1;
|
|
20
|
-
assert.equal(options.redirect, 'error');
|
|
21
|
-
return new Response('ok');
|
|
22
|
-
},
|
|
23
|
-
privateFetch: async () => {
|
|
24
|
-
privateCalls += 1;
|
|
25
|
-
return new Response('wrong lane');
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
);
|
|
29
|
-
assert.equal(result.exitCode, 0);
|
|
30
|
-
assert.equal(result.stdout, 'ok');
|
|
31
|
-
assert.equal(publicCalls, 1);
|
|
32
|
-
assert.equal(privateCalls, 0);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
test('explicit private HTTP hooks preserve their opt-in fetch lane', async () => {
|
|
36
|
-
let publicCalls = 0;
|
|
37
|
-
let privateCalls = 0;
|
|
38
|
-
const result = await runHttpHandler(
|
|
39
|
-
{ type: 'http', url: 'http://127.0.0.1/hook', allowPrivateHosts: true },
|
|
40
|
-
{ ok: true },
|
|
41
|
-
'Stop',
|
|
42
|
-
{
|
|
43
|
-
publicFetch: async () => {
|
|
44
|
-
publicCalls += 1;
|
|
45
|
-
return new Response('wrong lane');
|
|
46
|
-
},
|
|
47
|
-
privateFetch: async () => {
|
|
48
|
-
privateCalls += 1;
|
|
49
|
-
return new Response('local');
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
);
|
|
53
|
-
assert.equal(result.exitCode, 0);
|
|
54
|
-
assert.equal(result.stdout, 'local');
|
|
55
|
-
assert.equal(publicCalls, 0);
|
|
56
|
-
assert.equal(privateCalls, 1);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
test('public HTTP hooks reject private DNS answers before connecting', async () => {
|
|
60
|
-
const originalLookup = dns.promises.lookup;
|
|
61
|
-
dns.promises.lookup = async () => [{ address: '127.0.0.1', family: 4 }];
|
|
62
|
-
try {
|
|
63
|
-
const result = await runHttpHandler(
|
|
64
|
-
{ type: 'http', url: 'https://rebinding.example/hook' },
|
|
65
|
-
{ ok: true },
|
|
66
|
-
'Stop',
|
|
67
|
-
);
|
|
68
|
-
assert.equal(result.exitCode, -1);
|
|
69
|
-
assert.match(result.stderr, /private address/);
|
|
70
|
-
} finally {
|
|
71
|
-
dns.promises.lookup = originalLookup;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('HTTP hook responses enforce the shared memory cap', async () => {
|
|
76
|
-
const result = await runHttpHandler(
|
|
77
|
-
{ type: 'http', url: 'https://example.com/hook' },
|
|
78
|
-
{ ok: true },
|
|
79
|
-
'Stop',
|
|
80
|
-
{
|
|
81
|
-
publicFetch: async () => new Response('x', {
|
|
82
|
-
headers: { 'content-length': String(MAX_HTTP_HOOK_RESPONSE_BYTES + 1) },
|
|
83
|
-
}),
|
|
84
|
-
},
|
|
85
|
-
);
|
|
86
|
-
assert.equal(result.exitCode, -1);
|
|
87
|
-
assert.match(result.stderr, /byte limit/);
|
|
88
|
-
});
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { spawn } from 'node:child_process';
|
|
3
|
-
import {
|
|
4
|
-
existsSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
mkdtempSync,
|
|
7
|
-
readFileSync,
|
|
8
|
-
rmSync,
|
|
9
|
-
statSync,
|
|
10
|
-
writeFileSync,
|
|
11
|
-
} from 'node:fs';
|
|
12
|
-
import { tmpdir } from 'node:os';
|
|
13
|
-
import { join } from 'node:path';
|
|
14
|
-
import { setTimeout as sleep } from 'node:timers/promises';
|
|
15
|
-
import test from 'node:test';
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
_publishManagedPluginRoot,
|
|
19
|
-
addPlugin,
|
|
20
|
-
listRegisteredPlugins,
|
|
21
|
-
setPluginEnabled,
|
|
22
|
-
} from './plugin-admin.mjs';
|
|
23
|
-
import { hookConfigEntries } from './hook-bus/config.mjs';
|
|
24
|
-
|
|
25
|
-
test('plugin registry persists atomically with owner-only permissions', () => {
|
|
26
|
-
const root = mkdtempSync(join(tmpdir(), 'mixdog-plugin-registry-'));
|
|
27
|
-
const source = join(root, 'local-plugin');
|
|
28
|
-
const dataDir = join(root, 'data');
|
|
29
|
-
try {
|
|
30
|
-
mkdirSync(source, { recursive: true });
|
|
31
|
-
writeFileSync(join(source, 'plugin.json'), JSON.stringify({ name: 'local-test' }));
|
|
32
|
-
addPlugin(source, { dataDir });
|
|
33
|
-
|
|
34
|
-
const registryPath = join(dataDir, 'plugins', 'registry.json');
|
|
35
|
-
const registry = JSON.parse(readFileSync(registryPath, 'utf8'));
|
|
36
|
-
assert.equal(registry.plugins.length, 1);
|
|
37
|
-
assert.equal(listRegisteredPlugins({ dataDir })[0].name, 'local-test');
|
|
38
|
-
assert.equal(listRegisteredPlugins({ dataDir })[0].enabled, true);
|
|
39
|
-
assert.equal(hookConfigEntries(dataDir, root).some((entry) => entry.sourceType === 'plugin'), true);
|
|
40
|
-
setPluginEnabled('local-test', false, { dataDir });
|
|
41
|
-
assert.equal(listRegisteredPlugins({ dataDir })[0].enabled, false);
|
|
42
|
-
assert.equal(hookConfigEntries(dataDir, root).some((entry) => entry.sourceType === 'plugin'), false);
|
|
43
|
-
if (process.platform !== 'win32') {
|
|
44
|
-
assert.equal(statSync(registryPath).mode & 0o777, 0o600);
|
|
45
|
-
}
|
|
46
|
-
} finally {
|
|
47
|
-
rmSync(root, { recursive: true, force: true });
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
test('plugin Git sources reject insecure transport and embedded credentials', () => {
|
|
52
|
-
assert.throws(
|
|
53
|
-
() => addPlugin('http://plugins.example.test/example.git'),
|
|
54
|
-
/must use HTTPS or SSH/,
|
|
55
|
-
);
|
|
56
|
-
assert.throws(
|
|
57
|
-
() => addPlugin('https://token@plugins.example.test/example.git'),
|
|
58
|
-
/must not contain credentials/,
|
|
59
|
-
);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test('managed plugin publish rolls back the previous install on replacement failure', () => {
|
|
63
|
-
const base = mkdtempSync(join(tmpdir(), 'mixdog-plugin-publish-'));
|
|
64
|
-
const root = join(base, 'plugin');
|
|
65
|
-
const missing = join(base, 'missing');
|
|
66
|
-
try {
|
|
67
|
-
mkdirSync(root);
|
|
68
|
-
writeFileSync(join(root, 'version.txt'), 'old');
|
|
69
|
-
assert.throws(() => _publishManagedPluginRoot(root, missing), /ENOENT|no such file/i);
|
|
70
|
-
assert.equal(readFileSync(join(root, 'version.txt'), 'utf8'), 'old');
|
|
71
|
-
assert.equal(existsSync(`${root}.backup`), false);
|
|
72
|
-
|
|
73
|
-
const next = join(base, 'next');
|
|
74
|
-
mkdirSync(next);
|
|
75
|
-
writeFileSync(join(next, 'version.txt'), 'new');
|
|
76
|
-
_publishManagedPluginRoot(root, next);
|
|
77
|
-
assert.equal(readFileSync(join(root, 'version.txt'), 'utf8'), 'new');
|
|
78
|
-
assert.equal(existsSync(`${root}.backup`), false);
|
|
79
|
-
} finally {
|
|
80
|
-
rmSync(base, { recursive: true, force: true });
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
test('plugin registry mutation re-reads under the cross-process lock', async () => {
|
|
85
|
-
const root = mkdtempSync(join(tmpdir(), 'mixdog-plugin-concurrent-'));
|
|
86
|
-
const childSource = join(root, 'child-plugin');
|
|
87
|
-
const parentSource = join(root, 'parent-plugin');
|
|
88
|
-
const dataDir = join(root, 'data');
|
|
89
|
-
const registry = join(dataDir, 'plugins', 'registry.json');
|
|
90
|
-
const marker = join(root, 'locked');
|
|
91
|
-
mkdirSync(childSource);
|
|
92
|
-
mkdirSync(parentSource);
|
|
93
|
-
writeFileSync(join(childSource, 'plugin.json'), JSON.stringify({ name: 'child-plugin' }));
|
|
94
|
-
writeFileSync(join(parentSource, 'plugin.json'), JSON.stringify({ name: 'parent-plugin' }));
|
|
95
|
-
const atomicUrl = new URL('../runtime/shared/atomic-file.mjs', import.meta.url).href;
|
|
96
|
-
const script = `
|
|
97
|
-
import { mkdirSync, writeFileSync } from 'node:fs';
|
|
98
|
-
import { dirname } from 'node:path';
|
|
99
|
-
import { withFileLockSync, writeJsonAtomicSync } from ${JSON.stringify(atomicUrl)};
|
|
100
|
-
const registry = process.env.MIXDOG_TEST_REGISTRY;
|
|
101
|
-
const marker = process.env.MIXDOG_TEST_MARKER;
|
|
102
|
-
const source = process.env.MIXDOG_TEST_SOURCE;
|
|
103
|
-
mkdirSync(dirname(registry), { recursive: true });
|
|
104
|
-
withFileLockSync(registry + '.lock', () => {
|
|
105
|
-
writeFileSync(marker, 'locked');
|
|
106
|
-
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 250);
|
|
107
|
-
writeJsonAtomicSync(registry, {
|
|
108
|
-
version: 1,
|
|
109
|
-
plugins: [{
|
|
110
|
-
id: 'child-plugin',
|
|
111
|
-
source,
|
|
112
|
-
sourceType: 'local',
|
|
113
|
-
root: source,
|
|
114
|
-
managed: false,
|
|
115
|
-
name: 'child-plugin',
|
|
116
|
-
title: 'child-plugin',
|
|
117
|
-
}],
|
|
118
|
-
}, { lock: false, secret: true, fsyncDir: true });
|
|
119
|
-
}, { secret: true });
|
|
120
|
-
`;
|
|
121
|
-
const child = spawn(process.execPath, ['--input-type=module', '-e', script], {
|
|
122
|
-
env: {
|
|
123
|
-
...process.env,
|
|
124
|
-
MIXDOG_TEST_REGISTRY: registry,
|
|
125
|
-
MIXDOG_TEST_MARKER: marker,
|
|
126
|
-
MIXDOG_TEST_SOURCE: childSource,
|
|
127
|
-
},
|
|
128
|
-
stdio: ['ignore', 'ignore', 'pipe'],
|
|
129
|
-
});
|
|
130
|
-
let stderr = '';
|
|
131
|
-
child.stderr.setEncoding('utf8');
|
|
132
|
-
child.stderr.on('data', (chunk) => { stderr += chunk; });
|
|
133
|
-
const exited = new Promise((resolve, reject) => {
|
|
134
|
-
child.on('error', reject);
|
|
135
|
-
child.on('exit', (code) => {
|
|
136
|
-
if (code === 0) resolve();
|
|
137
|
-
else reject(new Error(stderr || `child exited ${code}`));
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
try {
|
|
141
|
-
for (let attempt = 0; attempt < 200 && !existsSync(marker); attempt += 1) {
|
|
142
|
-
await sleep(10);
|
|
143
|
-
}
|
|
144
|
-
assert.equal(existsSync(marker), true, stderr || 'child did not acquire registry lock');
|
|
145
|
-
addPlugin(parentSource, { dataDir });
|
|
146
|
-
await exited;
|
|
147
|
-
assert.deepEqual(
|
|
148
|
-
listRegisteredPlugins({ dataDir }).map((plugin) => plugin.name).sort(),
|
|
149
|
-
['child-plugin', 'parent-plugin'],
|
|
150
|
-
);
|
|
151
|
-
} finally {
|
|
152
|
-
if (child.exitCode === null) child.kill();
|
|
153
|
-
await exited.catch(() => {});
|
|
154
|
-
rmSync(root, { recursive: true, force: true });
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
test('plugin registry corruption fails closed without overwriting evidence', () => {
|
|
159
|
-
const root = mkdtempSync(join(tmpdir(), 'mixdog-plugin-corrupt-'));
|
|
160
|
-
const source = join(root, 'local-plugin');
|
|
161
|
-
const dataDir = join(root, 'data');
|
|
162
|
-
const registry = join(dataDir, 'plugins', 'registry.json');
|
|
163
|
-
try {
|
|
164
|
-
mkdirSync(source, { recursive: true });
|
|
165
|
-
mkdirSync(join(dataDir, 'plugins'), { recursive: true });
|
|
166
|
-
writeFileSync(join(source, 'plugin.json'), JSON.stringify({ name: 'local-test' }));
|
|
167
|
-
writeFileSync(registry, '{corrupt');
|
|
168
|
-
assert.throws(() => addPlugin(source, { dataDir }), /registry is corrupt/);
|
|
169
|
-
assert.equal(readFileSync(registry, 'utf8'), '{corrupt');
|
|
170
|
-
} finally {
|
|
171
|
-
rmSync(root, { recursive: true, force: true });
|
|
172
|
-
}
|
|
173
|
-
});
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import assert from 'node:assert/strict';
|
|
2
|
-
import { fork } from 'node:child_process';
|
|
3
|
-
import { mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
4
|
-
import { tmpdir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import test from 'node:test';
|
|
7
|
-
|
|
8
|
-
const CLIENT_URL = new URL('./session-runtime-agent-control-client.mjs', import.meta.url).href;
|
|
9
|
-
|
|
10
|
-
test('runtime shard Agent client sends serializable context and receives the routed result', async () => {
|
|
11
|
-
const dir = await mkdtemp(join(tmpdir(), 'mixdog-agent-control-client-'));
|
|
12
|
-
const entry = join(dir, 'client.mjs');
|
|
13
|
-
await writeFile(entry, `
|
|
14
|
-
process.env.MIXDOG_SESSION_RUNTIME_WORKER_PID = String(process.pid);
|
|
15
|
-
const client = await import(${JSON.stringify(CLIENT_URL)});
|
|
16
|
-
const value = await client.executeRemoteAgentControl(
|
|
17
|
-
{ type: 'spawn', tag: 'routed', agent: 'worker', prompt: 'run' },
|
|
18
|
-
{
|
|
19
|
-
callerCwd: 'C:/Project/test',
|
|
20
|
-
invocationSource: 'model-tool',
|
|
21
|
-
callerSessionId: 'sess_lead',
|
|
22
|
-
clientHostPid: 4242,
|
|
23
|
-
},
|
|
24
|
-
);
|
|
25
|
-
process.send({ type: 'report', value });
|
|
26
|
-
`, 'utf8');
|
|
27
|
-
|
|
28
|
-
try {
|
|
29
|
-
const observed = await new Promise((resolve, reject) => {
|
|
30
|
-
const child = fork(entry, [], {
|
|
31
|
-
stdio: ['ignore', 'ignore', 'pipe', 'ipc'],
|
|
32
|
-
env: { ...process.env },
|
|
33
|
-
});
|
|
34
|
-
const timer = setTimeout(() => {
|
|
35
|
-
try { child.kill(); } catch {}
|
|
36
|
-
reject(new Error('agent control client test timed out'));
|
|
37
|
-
}, 10_000);
|
|
38
|
-
child.on('message', (message) => {
|
|
39
|
-
if (message?.type === 'agent-control') {
|
|
40
|
-
assert.deepEqual(message.args, {
|
|
41
|
-
type: 'spawn',
|
|
42
|
-
tag: 'routed',
|
|
43
|
-
agent: 'worker',
|
|
44
|
-
prompt: 'run',
|
|
45
|
-
});
|
|
46
|
-
assert.deepEqual(message.context, {
|
|
47
|
-
callerCwd: 'C:/Project/test',
|
|
48
|
-
invocationSource: 'model-tool',
|
|
49
|
-
callerSessionId: 'sess_lead',
|
|
50
|
-
clientHostPid: 4242,
|
|
51
|
-
});
|
|
52
|
-
child.send({
|
|
53
|
-
type: 'agent-control-result',
|
|
54
|
-
controlId: message.controlId,
|
|
55
|
-
ok: true,
|
|
56
|
-
value: 'agent task: task_routed',
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
if (message?.type !== 'report') return;
|
|
61
|
-
clearTimeout(timer);
|
|
62
|
-
try { child.kill(); } catch {}
|
|
63
|
-
resolve(message.value);
|
|
64
|
-
});
|
|
65
|
-
child.on('error', reject);
|
|
66
|
-
});
|
|
67
|
-
assert.equal(observed, 'agent task: task_routed');
|
|
68
|
-
} finally {
|
|
69
|
-
await rm(dir, { recursive: true, force: true });
|
|
70
|
-
}
|
|
71
|
-
});
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// Cold-start cancellation contract, exercised against the REAL runtime worker
|
|
2
|
-
// child (no stub): a cancel that arrives before or during the dispatch's
|
|
3
|
-
// module/provider cold start must never be answered "not running" and then let
|
|
4
|
-
// the dispatch run anyway.
|
|
5
|
-
import assert from 'node:assert/strict';
|
|
6
|
-
import { fork } from 'node:child_process';
|
|
7
|
-
import { mkdtemp, rm } from 'node:fs/promises';
|
|
8
|
-
import { tmpdir } from 'node:os';
|
|
9
|
-
import { dirname, join } from 'node:path';
|
|
10
|
-
import { fileURLToPath } from 'node:url';
|
|
11
|
-
import test from 'node:test';
|
|
12
|
-
|
|
13
|
-
const WORKER_ENTRY = fileURLToPath(new URL('./session-runtime-worker.mjs', import.meta.url));
|
|
14
|
-
const REPO_ROOT = join(dirname(WORKER_ENTRY), '..', '..');
|
|
15
|
-
|
|
16
|
-
function startWorker(runtimeRoot) {
|
|
17
|
-
const child = fork(WORKER_ENTRY, [], {
|
|
18
|
-
cwd: REPO_ROOT,
|
|
19
|
-
execArgv: [],
|
|
20
|
-
stdio: ['ignore', 'ignore', 'pipe', 'ipc'],
|
|
21
|
-
env: {
|
|
22
|
-
...process.env,
|
|
23
|
-
MIXDOG_RUNTIME_ROOT: runtimeRoot,
|
|
24
|
-
MIXDOG_DATA_DIR: runtimeRoot,
|
|
25
|
-
MIXDOG_SESSION_RUNTIME_SHARD: '0',
|
|
26
|
-
MIXDOG_SESSION_RUNTIME_SHARD_COUNT: '2',
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
const responses = new Map();
|
|
30
|
-
const waiters = new Map();
|
|
31
|
-
child.on('message', (message) => {
|
|
32
|
-
if (message?.type !== 'response') return;
|
|
33
|
-
const id = String(message.requestId || '');
|
|
34
|
-
const waiter = waiters.get(id);
|
|
35
|
-
if (waiter) {
|
|
36
|
-
waiters.delete(id);
|
|
37
|
-
waiter(message);
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
responses.set(id, message);
|
|
41
|
-
});
|
|
42
|
-
const send = (payload) => child.send(payload);
|
|
43
|
-
const wait = (requestId, timeoutMs = 30_000) => new Promise((resolve, reject) => {
|
|
44
|
-
const settled = responses.get(requestId);
|
|
45
|
-
if (settled) {
|
|
46
|
-
responses.delete(requestId);
|
|
47
|
-
resolve(settled);
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
const timer = setTimeout(
|
|
51
|
-
() => reject(new Error(`timed out waiting for ${requestId}`)),
|
|
52
|
-
timeoutMs,
|
|
53
|
-
);
|
|
54
|
-
waiters.set(requestId, (message) => { clearTimeout(timer); resolve(message); });
|
|
55
|
-
});
|
|
56
|
-
return { child, send, wait };
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
async function stopWorker(worker) {
|
|
60
|
-
try {
|
|
61
|
-
worker.send({ type: 'shutdown', requestId: 'shutdown-1', reason: 'test complete' });
|
|
62
|
-
await worker.wait('shutdown-1', 8_000).catch(() => {});
|
|
63
|
-
await new Promise((resolve) => setTimeout(resolve, 250));
|
|
64
|
-
} finally {
|
|
65
|
-
try { worker.child.kill(); } catch {}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
test('a cancel that arrives before the dispatch is retained and aborts it', async () => {
|
|
70
|
-
const runtimeRoot = await mkdtemp(join(tmpdir(), 'mixdog-dispatch-cancel-'));
|
|
71
|
-
const worker = startWorker(runtimeRoot);
|
|
72
|
-
try {
|
|
73
|
-
worker.send({
|
|
74
|
-
type: 'agent-dispatch-cancel',
|
|
75
|
-
requestId: 'cancel-early',
|
|
76
|
-
dispatchId: 'dispatch-cold',
|
|
77
|
-
reason: 'user aborted during cold start',
|
|
78
|
-
});
|
|
79
|
-
const cancel = await worker.wait('cancel-early', 15_000);
|
|
80
|
-
assert.equal(cancel.ok, true);
|
|
81
|
-
// Never "cancelled: false": an unknown id means not-registered-YET.
|
|
82
|
-
assert.equal(cancel.value.cancelled, true);
|
|
83
|
-
assert.equal(cancel.value.retained, true);
|
|
84
|
-
|
|
85
|
-
const startedAt = Date.now();
|
|
86
|
-
worker.send({
|
|
87
|
-
type: 'agent-dispatch',
|
|
88
|
-
requestId: 'dispatch-cold-1',
|
|
89
|
-
dispatchId: 'dispatch-cold',
|
|
90
|
-
agent: 'memory',
|
|
91
|
-
params: { prompt: 'must never run' },
|
|
92
|
-
});
|
|
93
|
-
const dispatch = await worker.wait('dispatch-cold-1', 20_000);
|
|
94
|
-
assert.equal(dispatch.ok, false);
|
|
95
|
-
assert.match(String(dispatch.error?.message || ''), /user aborted during cold start/);
|
|
96
|
-
// The abort is adopted at registration — before the orchestrator/provider
|
|
97
|
-
// cold start, which alone takes seconds in this worker.
|
|
98
|
-
assert.ok(
|
|
99
|
-
Date.now() - startedAt < 3_000,
|
|
100
|
-
'aborted dispatch never entered module/provider setup',
|
|
101
|
-
);
|
|
102
|
-
} finally {
|
|
103
|
-
await stopWorker(worker);
|
|
104
|
-
await rm(runtimeRoot, { recursive: true, force: true });
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('a cancel racing a cold-start dispatch is never answered "not running"', async () => {
|
|
109
|
-
const runtimeRoot = await mkdtemp(join(tmpdir(), 'mixdog-dispatch-cancel-warm-'));
|
|
110
|
-
const worker = startWorker(runtimeRoot);
|
|
111
|
-
try {
|
|
112
|
-
worker.send({
|
|
113
|
-
type: 'agent-dispatch',
|
|
114
|
-
requestId: 'dispatch-warm-1',
|
|
115
|
-
dispatchId: 'dispatch-warm',
|
|
116
|
-
agent: 'memory',
|
|
117
|
-
params: { prompt: 'cancelled while importing' },
|
|
118
|
-
});
|
|
119
|
-
// The cold start compiles the orchestrator graph and blocks this loop, so
|
|
120
|
-
// the cancel frame can only be handled once that window closes. Whichever
|
|
121
|
-
// side wins, the abort must be honoured or retained — never dropped with
|
|
122
|
-
// `cancelled: false`, which is what let a canceled dispatch keep running.
|
|
123
|
-
worker.send({
|
|
124
|
-
type: 'agent-dispatch-cancel',
|
|
125
|
-
requestId: 'cancel-warm',
|
|
126
|
-
dispatchId: 'dispatch-warm',
|
|
127
|
-
reason: 'aborted mid cold start',
|
|
128
|
-
});
|
|
129
|
-
const cancel = await worker.wait('cancel-warm', 60_000);
|
|
130
|
-
assert.equal(cancel.ok, true);
|
|
131
|
-
assert.equal(cancel.value.cancelled, true);
|
|
132
|
-
|
|
133
|
-
const dispatch = await worker.wait('dispatch-warm-1', 60_000);
|
|
134
|
-
assert.equal(dispatch.ok, false);
|
|
135
|
-
} finally {
|
|
136
|
-
await stopWorker(worker);
|
|
137
|
-
await rm(runtimeRoot, { recursive: true, force: true });
|
|
138
|
-
}
|
|
139
|
-
});
|