@deepseek-ai/dsh-loader-smoke 0.0.1-rc.1
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 +28 -0
- package/README.i18n.yaml +6 -0
- package/README.md +25 -0
- package/README.zh.md +25 -0
- package/lib/index.js +211 -0
- package/lib/invariant.js +23 -0
- package/lib/types/agent-turn.d.ts +27 -0
- package/lib/types/index.d.ts +115 -0
- package/lib/types/invariant.d.ts +16 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, DeepSeek
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.i18n.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Bilingual-pair consistency record (docs/i18n/README.md): the git blob hash of each
|
|
2
|
+
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
|
+
# after editing either side, bring the other along and re-record with:
|
|
4
|
+
# pnpm run verify-translation-pairing --write packages/support/loader-smoke/README.md
|
|
5
|
+
README.md: e5a33beb95f4e5940364cf309c8ea5fea60686f1
|
|
6
|
+
README.zh.md: 32c7af5bef050d6d46e91783468bdd0aa66e5ca0
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# `@deepseek-ai/dsh-loader-smoke`
|
|
2
|
+
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
Shared subprocess harness for tests that boot an app and `cordis.yml` through the Cordis Loader. `resolveExampleLaunch` selects local `src` mode (tsx and root tsconfig paths) or CI `lib` mode (plain Node and package exports) from an explicit mode or `DSH_EXAMPLE_MODE`.
|
|
6
|
+
|
|
7
|
+
`runLoaderSmoke` accepts bin and config paths, optional complete bin arguments, environment overrides, stdin, pre-run setup, and pre-cleanup inspection. It owns the isolated cwd, DSH homes, diagnostics, deadline, termination, EOF, and cleanup; it returns both streams after a zero exit and rejects with both streams on failure.
|
|
8
|
+
|
|
9
|
+
`runFixtureTurn` drives one task through exactly one configured root agent, forwards canonical events after that task reaches the durable inbox, flushes the session, and returns the final assistant text plus accumulated usage. Example-local drivers retain configuration, rendering, and assertion ownership.
|
|
10
|
+
|
|
11
|
+
This is support-tier test infrastructure, not product API.
|
|
12
|
+
|
|
13
|
+
## Model Experience
|
|
14
|
+
|
|
15
|
+
None, as the test harness submits only the consuming test's ordinary user task and delegates prompt and tool composition to the loaded tree.
|
|
16
|
+
|
|
17
|
+
#### KV Cache effect
|
|
18
|
+
|
|
19
|
+
None beyond the loaded tree; the helper neither changes the request prefix nor retains state across runs.
|
|
20
|
+
|
|
21
|
+
## Known Limitations and Deferred Work
|
|
22
|
+
|
|
23
|
+
- **Built mode requires a prior build** — the config must also resolve every named package upward through `examples/node_modules`.
|
|
24
|
+
- **Captured stdout and stderr are bounded only by execa's default 100 MB `maxBuffer`** — a runaway child is terminated at that ceiling rather than at a smoke-chosen budget.
|
|
25
|
+
- **Timeout kills only the direct child** — a process tree spawned by a faulty fixture can outlive the smoke and needs external cleanup.
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# `@deepseek-ai/dsh-loader-smoke`
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
用于测试通过 Cordis Loader 启动应用和 `cordis.yml` 的共享子进程 harness。`resolveExampleLaunch` 选择本地 `src` mode(tsx 和根 tsconfig 路径)或 CI `lib` mode(普通 Node 和包导出);选择依据为显式 mode 或 `DSH_EXAMPLE_MODE`。
|
|
6
|
+
|
|
7
|
+
`runLoaderSmoke` 接受可执行文件路径和配置路径、可选的完整可执行文件参数、环境变量覆盖、标准输入、运行前准备和清理前检查。它负责隔离工作目录、DSH 主目录、诊断、截止时间、终止、EOF 和清理;进程以零状态退出后返回两个流,失败时则返回拒绝并附带两个流。
|
|
8
|
+
|
|
9
|
+
`runFixtureTurn` 通过恰好一个已配置的根 agent(智能体)驱动一项任务,在该任务进入持久收件箱后转发规范事件,刷写会话,并返回最终 assistant 文本和累计用量。示例本地 driver 继续负责配置、渲染和断言。
|
|
10
|
+
|
|
11
|
+
这是支持层测试基础设施,而非产品 API。
|
|
12
|
+
|
|
13
|
+
## 模型体验
|
|
14
|
+
|
|
15
|
+
无,因为测试 harness 仅提交调用方测试的普通用户任务,并将提示词和工具组装交由已加载的树负责。
|
|
16
|
+
|
|
17
|
+
#### KV Cache 影响
|
|
18
|
+
|
|
19
|
+
除已加载树本身的影响外,无其他影响;该 helper 既不更改请求前缀,也不跨运行保留状态。
|
|
20
|
+
|
|
21
|
+
## 已知限制与暂缓事项
|
|
22
|
+
|
|
23
|
+
- **构建模式需要事先构建**:配置还必须能够通过 `examples/node_modules` 向上解析每个命名包。
|
|
24
|
+
- **捕获的 stdout 和 stderr 仅受 execa 默认 100 MB `maxBuffer` 约束**:失控子进程会在该上限处被终止,而不是在冒烟测试自选的预算处。
|
|
25
|
+
- **超时只终止直接子进程**:有故障的 fixture(测试前置数据)spawn 的进程树可能比冒烟测试存活更久,需要外部清理。
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { execa } from "execa";
|
|
5
|
+
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
6
|
+
//#region lib/types/agent-turn.js
|
|
7
|
+
/**
|
|
8
|
+
* Test-only direct-agent turn driver shared by assembled Loader fixtures.
|
|
9
|
+
* @module @deepseek-ai/dsh-loader-smoke/agent-turn
|
|
10
|
+
*/
|
|
11
|
+
function addUsage(total, step) {
|
|
12
|
+
const next = {
|
|
13
|
+
inputTokens: (total?.inputTokens ?? 0) + step.inputTokens,
|
|
14
|
+
outputTokens: (total?.outputTokens ?? 0) + step.outputTokens
|
|
15
|
+
};
|
|
16
|
+
for (const key of [
|
|
17
|
+
"cacheReadTokens",
|
|
18
|
+
"cacheWriteTokens",
|
|
19
|
+
"reasoningTokens"
|
|
20
|
+
]) if (total?.[key] !== void 0 || step[key] !== void 0) next[key] = (total?.[key] ?? 0) + (step[key] ?? 0);
|
|
21
|
+
return next;
|
|
22
|
+
}
|
|
23
|
+
function assistantText(event) {
|
|
24
|
+
const blocks = event.data.message.content.filter((block) => block.type === "text");
|
|
25
|
+
return blocks.length === 0 ? void 0 : blocks.map((block) => block.text).join("");
|
|
26
|
+
}
|
|
27
|
+
function onlyRootAgent(ctx) {
|
|
28
|
+
const agents = ctx.get("agents")?.roots() ?? [];
|
|
29
|
+
const [agent] = agents;
|
|
30
|
+
if (agent === void 0 || agents.length !== 1) throw new Error(`fixture turn requires exactly one top-level agent, found ${agents.length}`);
|
|
31
|
+
return agent;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Drive one task from its durable inbox receipt through whole-agent idle.
|
|
35
|
+
* @param ctx - settled Loader context with exactly one configured root agent.
|
|
36
|
+
* @param options - task and optional canonical-event observer.
|
|
37
|
+
* @returns the final assistant text and accumulated model usage.
|
|
38
|
+
*/
|
|
39
|
+
async function runFixtureTurn(ctx, options) {
|
|
40
|
+
const agent = onlyRootAgent(ctx);
|
|
41
|
+
await agent.whenIdle();
|
|
42
|
+
const message = createUserMessage({
|
|
43
|
+
content: [{
|
|
44
|
+
type: "text",
|
|
45
|
+
text: options.task
|
|
46
|
+
}],
|
|
47
|
+
source: { kind: "user" }
|
|
48
|
+
});
|
|
49
|
+
let received = false;
|
|
50
|
+
let output = "";
|
|
51
|
+
const usageByStep = /* @__PURE__ */ new Map();
|
|
52
|
+
const disposeListener = ctx.on("session/event", (session, event) => {
|
|
53
|
+
if (session !== agent.session) return;
|
|
54
|
+
if (!received) {
|
|
55
|
+
if (event.type !== "agent/inbox/spliced" || !event.data.inserted.some((inserted) => inserted.id === message.id)) return;
|
|
56
|
+
received = true;
|
|
57
|
+
}
|
|
58
|
+
options.onEvent?.(session.id, event);
|
|
59
|
+
if (event.type === "assistant/chunk" && event.data.chunk.type === "usage") usageByStep.set(`${event.data.turn}/${event.data.step}`, event.data.chunk.usage);
|
|
60
|
+
if (event.type === "assistant/message") {
|
|
61
|
+
output = assistantText(event) ?? output;
|
|
62
|
+
if (event.data.usage !== void 0) usageByStep.set(`${event.data.turn}/${event.data.step}`, event.data.usage);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
try {
|
|
66
|
+
agent.followup(message);
|
|
67
|
+
await agent.whenIdle();
|
|
68
|
+
} finally {
|
|
69
|
+
disposeListener();
|
|
70
|
+
}
|
|
71
|
+
await ctx.sessions.flush(agent.session);
|
|
72
|
+
const usage = [...usageByStep.values()].reduce(addUsage, void 0);
|
|
73
|
+
return {
|
|
74
|
+
type: "result",
|
|
75
|
+
sessionId: agent.session.id,
|
|
76
|
+
output,
|
|
77
|
+
...usage === void 0 ? {} : { usage }
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region lib/types/index.js
|
|
82
|
+
/**
|
|
83
|
+
* Shared subprocess harness for keyless example smokes that boot a real
|
|
84
|
+
* `cordis.yml` through an app bin and Cordis Loader.
|
|
85
|
+
*
|
|
86
|
+
* It also owns the mode-aware launch resolver every example subprocess harness shares
|
|
87
|
+
* ({@link resolveExampleLaunch}): booting an example bin from TypeScript source under `tsx` (the
|
|
88
|
+
* zero-build dev path, resolving `@deepseek-ai/dsh-*` / `@cordisjs/*` through the tsconfig `paths`
|
|
89
|
+
* map) or from built `lib/` under plain Node (resolving bare packages through real `exports`, as an
|
|
90
|
+
* installed consumer does, while Node type-strips relative example-local TypeScript plugins).
|
|
91
|
+
*
|
|
92
|
+
* @module @deepseek-ai/dsh-loader-smoke
|
|
93
|
+
*/
|
|
94
|
+
const DEFAULT_PROCESS_TIMEOUT_MS = 3e4;
|
|
95
|
+
/** Vitest deadline that leaves room for the subprocess-owned 30-second diagnostic timeout. */
|
|
96
|
+
const LOADER_SMOKE_TEST_TIMEOUT_MS = 45e3;
|
|
97
|
+
/** Environment variable selecting the mode; CI sets it to `lib`, dev leaves it unset (`src`). */
|
|
98
|
+
const EXAMPLE_MODE_ENV = "DSH_EXAMPLE_MODE";
|
|
99
|
+
/**
|
|
100
|
+
* Parse an {@link ExampleMode} from a raw string, defaulting to `src` when absent so an unset
|
|
101
|
+
* environment reproduces the dev/tsx behavior. Throws on any other value rather than silently
|
|
102
|
+
* falling back, so a typo in a gate's env fails loud.
|
|
103
|
+
* @param raw - the raw value; defaults to `process.env.DSH_EXAMPLE_MODE`.
|
|
104
|
+
* @returns the validated mode.
|
|
105
|
+
*/
|
|
106
|
+
function resolveExampleMode(raw = process.env[EXAMPLE_MODE_ENV]) {
|
|
107
|
+
switch (raw) {
|
|
108
|
+
case void 0:
|
|
109
|
+
case "":
|
|
110
|
+
case "src": return "src";
|
|
111
|
+
case "lib": return "lib";
|
|
112
|
+
default: throw new Error(`${EXAMPLE_MODE_ENV} must be 'src' or 'lib', got ${JSON.stringify(raw)}.`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/** Derive the built-lib bin (`<pkg>/lib/<name>.js`) from a source bin (`<pkg>/src/<name>.ts`). */
|
|
116
|
+
function toLibBin(srcBin) {
|
|
117
|
+
const markerLength = 5;
|
|
118
|
+
const cut = Math.max(srcBin.lastIndexOf("/src/"), srcBin.lastIndexOf("\\src\\"));
|
|
119
|
+
if (cut === -1) throw new Error(`resolveExampleLaunch: expected a "/src/" segment or Windows equivalent in bin path ${JSON.stringify(srcBin)}.`);
|
|
120
|
+
const separator = srcBin.slice(cut, cut + 1);
|
|
121
|
+
const tail = srcBin.slice(cut + markerLength).replace(/\.ts$/, ".js");
|
|
122
|
+
return `${srcBin.slice(0, cut)}${separator}lib${separator}${tail}`;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Resolve how to spawn an example bin in the selected mode.
|
|
126
|
+
*
|
|
127
|
+
* `src` yields `node --import <tsx> <srcBin> <configArgs>` with `TSX_TSCONFIG_PATH` set so the
|
|
128
|
+
* tsconfig `paths` map resolves workspace imports to source. `lib` yields
|
|
129
|
+
* `node <libBin> <configArgs>` under plain Node with no tsx and no paths map, so
|
|
130
|
+
* bare package plugins resolve through real package `exports` into built `lib/`; relative example-local
|
|
131
|
+
* TypeScript plugins remain source files loaded through Node's built-in type stripping. Bare resolution
|
|
132
|
+
* requires the config to live below a workspace that declares its `cordis.yml` package dependencies.
|
|
133
|
+
*
|
|
134
|
+
* @param options - the source bin, config arguments, mode, and environment.
|
|
135
|
+
* @returns the command, argument vector, and mode-specific environment to spawn with.
|
|
136
|
+
*/
|
|
137
|
+
function resolveExampleLaunch(options) {
|
|
138
|
+
const mode = options.mode ?? resolveExampleMode();
|
|
139
|
+
const configArgs = options.configArgs ?? [];
|
|
140
|
+
const env = { ...options.env };
|
|
141
|
+
if (mode === "src") {
|
|
142
|
+
if (options.tsconfigPath === void 0) throw new Error("resolveExampleLaunch: 'src' mode needs tsconfigPath for the workspace paths map.");
|
|
143
|
+
const tsxLoader = import.meta.resolve("tsx");
|
|
144
|
+
env.TSX_TSCONFIG_PATH = options.tsconfigPath;
|
|
145
|
+
return {
|
|
146
|
+
command: process.execPath,
|
|
147
|
+
args: [
|
|
148
|
+
"--import",
|
|
149
|
+
tsxLoader,
|
|
150
|
+
options.srcBin,
|
|
151
|
+
...configArgs
|
|
152
|
+
],
|
|
153
|
+
env
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
command: process.execPath,
|
|
158
|
+
args: [options.libBin ?? toLibBin(options.srcBin), ...configArgs],
|
|
159
|
+
env
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Boot one real Loader tree from an isolated cwd, close stdin immediately, and
|
|
164
|
+
* await a clean exit. The helper owns process kill and temp-directory cleanup on
|
|
165
|
+
* every outcome, and picks src/lib via {@link resolveExampleLaunch}.
|
|
166
|
+
* @param options - example paths, mode, environment, and diagnostic identity.
|
|
167
|
+
* @returns captured stdout and stderr after a zero exit.
|
|
168
|
+
*/
|
|
169
|
+
async function runLoaderSmoke(options) {
|
|
170
|
+
const cwd = await mkdtemp(join(tmpdir(), options.tempDirPrefix));
|
|
171
|
+
const processTimeoutMs = options.processTimeoutMs ?? DEFAULT_PROCESS_TIMEOUT_MS;
|
|
172
|
+
try {
|
|
173
|
+
await options.prepare?.(cwd);
|
|
174
|
+
const launch = resolveExampleLaunch({
|
|
175
|
+
srcBin: options.binScript,
|
|
176
|
+
libBin: options.libBinScript,
|
|
177
|
+
configArgs: options.binArgs ?? [options.configPath],
|
|
178
|
+
...options.mode !== void 0 ? { mode: options.mode } : {},
|
|
179
|
+
tsconfigPath: options.tsconfigPath,
|
|
180
|
+
env: {
|
|
181
|
+
DSH_HOME: join(cwd, ".dsh"),
|
|
182
|
+
DSH_AGENTS_HOME: join(cwd, ".agents"),
|
|
183
|
+
...options.env
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const result = await execa(launch.command, launch.args, {
|
|
187
|
+
cwd,
|
|
188
|
+
env: launch.env,
|
|
189
|
+
input: "",
|
|
190
|
+
timeout: processTimeoutMs,
|
|
191
|
+
killSignal: "SIGKILL",
|
|
192
|
+
reject: false,
|
|
193
|
+
stripFinalNewline: false
|
|
194
|
+
});
|
|
195
|
+
if (result.timedOut) throw new Error(`${options.label} did not exit within ${processTimeoutMs / 1e3}s. stdout:\n${result.stdout}\nstderr:\n${result.stderr}`);
|
|
196
|
+
const expectedExitCode = options.expectedExitCode ?? 0;
|
|
197
|
+
if (result.exitCode !== expectedExitCode) throw new Error(`${options.label} exited ${String(result.exitCode)} (expected ${expectedExitCode}). stdout:\n${result.stdout}\nstderr:\n${result.stderr}`);
|
|
198
|
+
await options.inspect?.(cwd);
|
|
199
|
+
return {
|
|
200
|
+
stdout: result.stdout,
|
|
201
|
+
stderr: result.stderr
|
|
202
|
+
};
|
|
203
|
+
} finally {
|
|
204
|
+
await rm(cwd, {
|
|
205
|
+
recursive: true,
|
|
206
|
+
force: true
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//#endregion
|
|
211
|
+
export { EXAMPLE_MODE_ENV, LOADER_SMOKE_TEST_TIMEOUT_MS, resolveExampleLaunch, resolveExampleMode, runFixtureTurn, runLoaderSmoke };
|
package/lib/invariant.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region lib/types/invariant.js
|
|
2
|
+
/**
|
|
3
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-loader-smoke`.
|
|
4
|
+
* @module @deepseek-ai/dsh-loader-smoke/invariant
|
|
5
|
+
*/
|
|
6
|
+
const PACKAGE_NAME = "@deepseek-ai/dsh-loader-smoke";
|
|
7
|
+
/** Cordis companion plugin name. */
|
|
8
|
+
const name = "loader-smoke-invariant";
|
|
9
|
+
/** Service required before the companion can reserve package ownership. */
|
|
10
|
+
const inject = ["invariants"];
|
|
11
|
+
/**
|
|
12
|
+
* No runtime invariant: this test-support package owns no production event stream or mutable data;
|
|
13
|
+
* consuming test suites exercise its behavior.
|
|
14
|
+
*/
|
|
15
|
+
const install = () => {};
|
|
16
|
+
/**
|
|
17
|
+
* Register this package's invariant companion.
|
|
18
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
19
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
20
|
+
*/
|
|
21
|
+
const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
22
|
+
//#endregion
|
|
23
|
+
export { apply, inject, name };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Test-only direct-agent turn driver shared by assembled Loader fixtures.
|
|
3
|
+
* @module @deepseek-ai/dsh-loader-smoke/agent-turn
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
import { type TokenUsage } from '@deepseek-ai/dsh-llm';
|
|
7
|
+
import type { SessionEvent } from '@deepseek-ai/dsh-session';
|
|
8
|
+
/** Result envelope consumed only by snapshot and composition tests. */
|
|
9
|
+
export interface FixtureTurnResult {
|
|
10
|
+
readonly type: 'result';
|
|
11
|
+
readonly sessionId: string;
|
|
12
|
+
readonly output: string;
|
|
13
|
+
readonly usage?: TokenUsage;
|
|
14
|
+
}
|
|
15
|
+
/** Options for one fixture turn against exactly one configured root agent. */
|
|
16
|
+
export interface FixtureTurnOptions {
|
|
17
|
+
readonly task: string;
|
|
18
|
+
readonly onEvent?: (sessionId: string, event: SessionEvent) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Drive one task from its durable inbox receipt through whole-agent idle.
|
|
22
|
+
* @param ctx - settled Loader context with exactly one configured root agent.
|
|
23
|
+
* @param options - task and optional canonical-event observer.
|
|
24
|
+
* @returns the final assistant text and accumulated model usage.
|
|
25
|
+
*/
|
|
26
|
+
export declare function runFixtureTurn(ctx: Context, options: FixtureTurnOptions): Promise<FixtureTurnResult>;
|
|
27
|
+
//# sourceMappingURL=agent-turn.d.ts.map
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared subprocess harness for keyless example smokes that boot a real
|
|
3
|
+
* `cordis.yml` through an app bin and Cordis Loader.
|
|
4
|
+
*
|
|
5
|
+
* It also owns the mode-aware launch resolver every example subprocess harness shares
|
|
6
|
+
* ({@link resolveExampleLaunch}): booting an example bin from TypeScript source under `tsx` (the
|
|
7
|
+
* zero-build dev path, resolving `@deepseek-ai/dsh-*` / `@cordisjs/*` through the tsconfig `paths`
|
|
8
|
+
* map) or from built `lib/` under plain Node (resolving bare packages through real `exports`, as an
|
|
9
|
+
* installed consumer does, while Node type-strips relative example-local TypeScript plugins).
|
|
10
|
+
*
|
|
11
|
+
* @module @deepseek-ai/dsh-loader-smoke
|
|
12
|
+
*/
|
|
13
|
+
export { runFixtureTurn, type FixtureTurnOptions, type FixtureTurnResult, } from './agent-turn.ts';
|
|
14
|
+
/** Vitest deadline that leaves room for the subprocess-owned 30-second diagnostic timeout. */
|
|
15
|
+
export declare const LOADER_SMOKE_TEST_TIMEOUT_MS: number;
|
|
16
|
+
/** Which artifact an example bin is booted from: unbuilt `src` via tsx, or built `lib` via plain Node. */
|
|
17
|
+
export type ExampleMode = 'src' | 'lib';
|
|
18
|
+
/** Environment variable selecting the mode; CI sets it to `lib`, dev leaves it unset (`src`). */
|
|
19
|
+
export declare const EXAMPLE_MODE_ENV = "DSH_EXAMPLE_MODE";
|
|
20
|
+
/**
|
|
21
|
+
* Parse an {@link ExampleMode} from a raw string, defaulting to `src` when absent so an unset
|
|
22
|
+
* environment reproduces the dev/tsx behavior. Throws on any other value rather than silently
|
|
23
|
+
* falling back, so a typo in a gate's env fails loud.
|
|
24
|
+
* @param raw - the raw value; defaults to `process.env.DSH_EXAMPLE_MODE`.
|
|
25
|
+
* @returns the validated mode.
|
|
26
|
+
*/
|
|
27
|
+
export declare function resolveExampleMode(raw?: string | undefined): ExampleMode;
|
|
28
|
+
/** Inputs to {@link resolveExampleLaunch}. */
|
|
29
|
+
export interface ExampleLaunchOptions {
|
|
30
|
+
/** Absolute path to the example bin's TypeScript source entry (`<pkg>/src/bin.ts`); the `lib` bin is derived from it. */
|
|
31
|
+
readonly srcBin: string;
|
|
32
|
+
/** Explicit plain-Node entry for `lib` mode; test fixtures may point this at Node-type-strippable TypeScript. */
|
|
33
|
+
readonly libBin?: string | undefined;
|
|
34
|
+
/** Arguments passed after the bin — the config, positional (`[configPath]`) or flagged (`['--config', configPath]`). */
|
|
35
|
+
readonly configArgs?: readonly string[];
|
|
36
|
+
/** The mode to launch in; defaults to {@link resolveExampleMode} of the environment. */
|
|
37
|
+
readonly mode?: ExampleMode;
|
|
38
|
+
/** Absolute repo tsconfig whose `paths` map resolves unbuilt workspace imports. Required in `src` mode, ignored in `lib`. */
|
|
39
|
+
readonly tsconfigPath?: string;
|
|
40
|
+
/** Extra environment entries the mode-specific ones layer over; the caller then merges the result over `process.env`. */
|
|
41
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
42
|
+
}
|
|
43
|
+
/** The resolved spawn: `spawn(command, args, { env: { ...process.env, ...env } })`. */
|
|
44
|
+
export interface ExampleLaunch {
|
|
45
|
+
/** The executable to spawn — always the current Node binary. */
|
|
46
|
+
readonly command: string;
|
|
47
|
+
/** Node flags, the resolved bin, then the caller's `configArgs`. */
|
|
48
|
+
readonly args: string[];
|
|
49
|
+
/** Mode-specific environment (`TSX_TSCONFIG_PATH` in `src`, nothing added in `lib`) layered over the caller's `env`. */
|
|
50
|
+
readonly env: NodeJS.ProcessEnv;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resolve how to spawn an example bin in the selected mode.
|
|
54
|
+
*
|
|
55
|
+
* `src` yields `node --import <tsx> <srcBin> <configArgs>` with `TSX_TSCONFIG_PATH` set so the
|
|
56
|
+
* tsconfig `paths` map resolves workspace imports to source. `lib` yields
|
|
57
|
+
* `node <libBin> <configArgs>` under plain Node with no tsx and no paths map, so
|
|
58
|
+
* bare package plugins resolve through real package `exports` into built `lib/`; relative example-local
|
|
59
|
+
* TypeScript plugins remain source files loaded through Node's built-in type stripping. Bare resolution
|
|
60
|
+
* requires the config to live below a workspace that declares its `cordis.yml` package dependencies.
|
|
61
|
+
*
|
|
62
|
+
* @param options - the source bin, config arguments, mode, and environment.
|
|
63
|
+
* @returns the command, argument vector, and mode-specific environment to spawn with.
|
|
64
|
+
*/
|
|
65
|
+
export declare function resolveExampleLaunch(options: ExampleLaunchOptions): ExampleLaunch;
|
|
66
|
+
/** Inputs that vary between real-Loader example smokes. */
|
|
67
|
+
export interface LoaderSmokeOptions {
|
|
68
|
+
/** Human-readable example name used in failure diagnostics. */
|
|
69
|
+
readonly label: string;
|
|
70
|
+
/** Prefix for the isolated temporary process cwd. */
|
|
71
|
+
readonly tempDirPrefix: string;
|
|
72
|
+
/** Absolute app-bin source path (`<pkg>/src/bin.ts`); the `lib` bin is derived from it. */
|
|
73
|
+
readonly binScript: string;
|
|
74
|
+
/** Explicit plain-Node entry for `lib` mode; intended for test fixtures outside a package `src/` tree. */
|
|
75
|
+
readonly libBinScript?: string | undefined;
|
|
76
|
+
/** Absolute real Loader config path, passed as the sole bin argument by default. */
|
|
77
|
+
readonly configPath: string;
|
|
78
|
+
/** Complete argv after the bin path; overrides the default `[configPath]`. */
|
|
79
|
+
readonly binArgs?: readonly string[];
|
|
80
|
+
/** Absolute repo tsconfig path used for unbuilt workspace-package resolution (required in `src` mode). */
|
|
81
|
+
readonly tsconfigPath: string;
|
|
82
|
+
/** Boot from source via tsx (`src`) or built lib via plain Node (`lib`); defaults to the environment's mode. */
|
|
83
|
+
readonly mode?: ExampleMode;
|
|
84
|
+
/** Environment overrides layered over the parent and isolated DSH homes. */
|
|
85
|
+
readonly env?: Readonly<NodeJS.ProcessEnv>;
|
|
86
|
+
/** Process deadline override for harness tests. */
|
|
87
|
+
readonly processTimeoutMs?: number;
|
|
88
|
+
/** Optional world-state setup run in the isolated cwd before process start. */
|
|
89
|
+
readonly prepare?: (cwd: string) => Promise<void> | void;
|
|
90
|
+
/** Optional world-state assertion run in the isolated cwd before cleanup. */
|
|
91
|
+
readonly inspect?: (cwd: string) => Promise<void> | void;
|
|
92
|
+
/**
|
|
93
|
+
* Exact process exit code this smoke expects; defaults to `0`. Scenarios
|
|
94
|
+
* pinning a designed failure surface (a one-shot turn ending in an error
|
|
95
|
+
* result) declare its nonzero exit here, and a run that exits any other
|
|
96
|
+
* way — including succeeding — still fails the smoke.
|
|
97
|
+
*/
|
|
98
|
+
readonly expectedExitCode?: number;
|
|
99
|
+
}
|
|
100
|
+
/** Captured output from a Loader smoke that exited successfully. */
|
|
101
|
+
export interface LoaderSmokeResult {
|
|
102
|
+
/** Complete stdout after clean exit. */
|
|
103
|
+
readonly stdout: string;
|
|
104
|
+
/** Complete stderr after clean exit. */
|
|
105
|
+
readonly stderr: string;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Boot one real Loader tree from an isolated cwd, close stdin immediately, and
|
|
109
|
+
* await a clean exit. The helper owns process kill and temp-directory cleanup on
|
|
110
|
+
* every outcome, and picks src/lib via {@link resolveExampleLaunch}.
|
|
111
|
+
* @param options - example paths, mode, environment, and diagnostic identity.
|
|
112
|
+
* @returns captured stdout and stderr after a zero exit.
|
|
113
|
+
*/
|
|
114
|
+
export declare function runLoaderSmoke(options: LoaderSmokeOptions): Promise<LoaderSmokeResult>;
|
|
115
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package-owned invariant companion for `@deepseek-ai/dsh-loader-smoke`.
|
|
3
|
+
* @module @deepseek-ai/dsh-loader-smoke/invariant
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
6
|
+
/** Cordis companion plugin name. */
|
|
7
|
+
export declare const name = "loader-smoke-invariant";
|
|
8
|
+
/** Service required before the companion can reserve package ownership. */
|
|
9
|
+
export declare const inject: string[];
|
|
10
|
+
/**
|
|
11
|
+
* Register this package's invariant companion.
|
|
12
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
13
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
14
|
+
*/
|
|
15
|
+
export declare const apply: (ctx: Context) => Promise<() => void>;
|
|
16
|
+
//# sourceMappingURL=invariant.d.ts.map
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deepseek-ai/dsh-loader-smoke",
|
|
3
|
+
"description": "Shared subprocess and direct-agent harness for keyless real-Loader example smoke tests",
|
|
4
|
+
"version": "0.0.1-rc.1",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "restricted"
|
|
7
|
+
},
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/deepseek-ai/deepseek-harness.git",
|
|
11
|
+
"directory": "packages/support/loader-smoke"
|
|
12
|
+
},
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "lib/index.js",
|
|
15
|
+
"types": "lib/types/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./lib/types/index.d.ts",
|
|
19
|
+
"default": "./lib/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./invariant": {
|
|
22
|
+
"types": "./lib/types/invariant.d.ts",
|
|
23
|
+
"default": "./lib/invariant.js"
|
|
24
|
+
},
|
|
25
|
+
"./src/*": "./src/*",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib/index.js",
|
|
30
|
+
"lib/invariant.js",
|
|
31
|
+
"lib/types/**/*.d.ts"
|
|
32
|
+
],
|
|
33
|
+
"license": "BSD-3-Clause",
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"execa": "^10.0.0",
|
|
36
|
+
"tsx": "^4.22.4"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@deepseek-ai/dsh-agent": "^0.0.1-rc.1",
|
|
40
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.1",
|
|
41
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
42
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1",
|
|
43
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.1",
|
|
47
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.1",
|
|
48
|
+
"@deepseek-ai/dsh-agent": "^0.0.1-rc.1",
|
|
49
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.1",
|
|
50
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.1"
|
|
51
|
+
}
|
|
52
|
+
}
|