147 lines
3.8 KiB
TypeScript
147 lines
3.8 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
isInterceptedWritingReportWrite,
|
|
isWritingFirstReportTurn,
|
|
shouldAutoOpenWritingArtifact,
|
|
} from "./writing-mode";
|
|
|
|
test("custom outputs markdown is always intercepted except the research stub", () => {
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/paper.md", undefined, undefined, true),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite(
|
|
"/mnt/user-data/outputs/report.md",
|
|
"research-report-j1",
|
|
undefined,
|
|
true,
|
|
),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("normal mode never intercepts outputs markdown writes", () => {
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/paper.md"),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m0", [
|
|
{ type: "human", content: "写一篇论文" },
|
|
]),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("report.md is intercepted for the whole first-report turn", () => {
|
|
const beforePipeline = [{ type: "human", content: "写一篇论文" }];
|
|
assert.equal(isWritingFirstReportTurn(beforePipeline), true);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite(
|
|
"/mnt/user-data/outputs/report.md",
|
|
"m1",
|
|
beforePipeline,
|
|
true,
|
|
),
|
|
true,
|
|
);
|
|
|
|
const inFlight = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
];
|
|
assert.equal(isWritingFirstReportTurn(inFlight), true);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m2", inFlight, true),
|
|
true,
|
|
);
|
|
|
|
const succeeded = [
|
|
...inFlight,
|
|
{
|
|
type: "tool",
|
|
name: "deep_research_report",
|
|
content: "研究报告已完成:已写入 report.md。",
|
|
},
|
|
];
|
|
assert.equal(isWritingFirstReportTurn(succeeded), true);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m3", succeeded, true),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("sandbox auto-open waits for report.md on the first-report turn", () => {
|
|
const firstTurn = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
];
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/research-notes.md", firstTurn, true),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/report.md", firstTurn, true),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("normal mode auto-opens every new artifact like before writing mode existed", () => {
|
|
const firstTurn = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
];
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/research-notes.md", firstTurn),
|
|
true,
|
|
);
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/report.md", firstTurn),
|
|
true,
|
|
);
|
|
});
|
|
|
|
test("Word artifacts stay download-only in every mode", () => {
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/fixed.docx"),
|
|
false,
|
|
);
|
|
assert.equal(
|
|
shouldAutoOpenWritingArtifact("/mnt/user-data/outputs/source.doc", [], true),
|
|
false,
|
|
);
|
|
});
|
|
|
|
test("a later user turn releases report.md live edits", () => {
|
|
const followUp = [
|
|
{ type: "human", content: "写一篇论文" },
|
|
{
|
|
type: "ai",
|
|
tool_calls: [{ name: "deep_research_report" }],
|
|
},
|
|
{
|
|
type: "tool",
|
|
name: "deep_research_report",
|
|
content: "研究报告已完成:已写入 report.md。",
|
|
},
|
|
{ type: "human", content: "把第二节改短一点" },
|
|
];
|
|
assert.equal(isWritingFirstReportTurn(followUp), false);
|
|
assert.equal(
|
|
isInterceptedWritingReportWrite("/mnt/user-data/outputs/report.md", "m4", followUp, true),
|
|
false,
|
|
);
|
|
});
|