@sanqianx/project-knowledge 5.0.30 → 5.0.31
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/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +21 -0
- package/_site/_test/appearance-settings-test.js +148 -0
- package/_site/_test/helpers/parallel-capture-safety-r5-cap-shell.js +606 -0
- package/_site/_test/helpers/parallel-capture-safety-r5-memory-shell.js +464 -0
- package/_site/_test/helpers/parallel-dock-acceptance-env.js +301 -0
- package/_site/_test/helpers/parallel-dock-acceptance-r2-env.js +378 -0
- package/_site/_test/helpers/parallel-dock-acceptance-r2-ui.js +314 -0
- package/_site/_test/helpers/parallel-dock-acceptance-ui.js +195 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-credential-preload.js +113 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-env.js +307 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-fixture.js +373 -0
- package/_site/_test/helpers/parallel-dock-isolation-r3-ui.js +314 -0
- package/_site/_test/helpers/parallel-engine-reconcile-r4-harness.js +340 -0
- package/_site/_test/helpers/parallel-engine-reconcile-r4-standin-analyzer.js +82 -0
- package/_site/_test/helpers/parallel-memory-capture-r3-cap-shell.js +605 -0
- package/_site/_test/helpers/parallel-memory-capture-r3-shell.js +176 -0
- package/_site/_test/helpers/parallel-memory-capture-r4-cap-shell.js +577 -0
- package/_site/_test/helpers/parallel-memory-injection-shell.js +723 -0
- package/_site/_test/helpers/parallel-memory-injection-wb-host.js +81 -0
- package/_site/_test/helpers/parallel-workbench-drafts-r5-fixture.js +295 -0
- package/_site/_test/helpers/parallel-workbench-drafts-r5-harness.js +573 -0
- package/_site/_test/helpers/parallel-workbench-drafts-r5-host.js +69 -0
- package/_site/_test/helpers/parallel-workbench-runtime-harness.js +587 -0
- package/_site/_test/helpers/qa-r45-harness.js +94 -0
- package/_site/_test/helpers/qa-r48-env.js +64 -0
- package/_site/_test/helpers/qa-r51-env.cjs +77 -0
- package/_site/_test/parallel-capture-safety-r5-cap006-probe.js +524 -0
- package/_site/_test/parallel-capture-safety-r5-cap008e-probe.js +577 -0
- package/_site/_test/parallel-capture-safety-r5-mem005-health-test.js +320 -0
- package/_site/_test/parallel-engine-reconcile-r4-eng007-probe.js +304 -0
- package/_site/_test/parallel-logging-acceptance-log003-probe.js +78 -0
- package/_site/_test/parallel-logging-acceptance-log004-probe.js +85 -0
- package/_site/_test/parallel-memory-capture-r3-cap001-probe.js +238 -0
- package/_site/_test/parallel-memory-capture-r3-cap006-probe.js +371 -0
- package/_site/_test/parallel-memory-capture-r3-cap008-probe.js +439 -0
- package/_site/_test/parallel-memory-capture-r3-mem005-persistence-test.js +271 -0
- package/_site/_test/parallel-memory-capture-r4-cap006-probe.js +519 -0
- package/_site/_test/parallel-memory-capture-r4-cap008e-probe.js +569 -0
- package/_site/_test/parallel-memory-capture-r4-mem005-health-test.js +314 -0
- package/_site/_test/parallel-memory-injection-origin-probe.js +412 -0
- package/_site/_test/parallel-memory-injection-probe.js +411 -0
- package/_site/_test/parallel-workbench-drafts-r4-probe.js +477 -0
- package/_site/_test/parallel-workbench-drafts-r5-chrome-env-bisect.js +89 -0
- package/_site/_test/parallel-workbench-drafts-r5-probe.js +593 -0
- package/_site/_test/parallel-workbench-runtime-minimax-probe.js +321 -0
- package/_site/_test/parallel-workbench-runtime-wb004-ordering.js +307 -0
- package/_site/_test/parallel-workbench-runtime-wb005-drafts.js +313 -0
- package/_site/_test/parallel-workbench-runtime-wb008-abort.js +321 -0
- package/_site/_test/qa-r45-offline-backfill-test.js +279 -0
- package/_site/_test/qa-r48-sys003-blank-secret-test.js +258 -0
- package/_site/_test/t07c-cln-001-002-007-coverage-test.js +135 -0
- package/_site/_test/t07d-git-rel-coverage-test.js +224 -0
- package/_site/_test/t07e-qta-coverage-test.js +195 -0
- package/_site/_test/t07f-mem-008-coverage-test.js +101 -0
- package/_site/lib/server-app.js +11 -2
- package/_site/lib/settings-store.js +43 -1
- package/module-runtime-manifest.json +6 -6
- package/package.json +1 -1
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/ui/index.html +18 -1
- package/ui/product.css +6 -2
- package/ui/product.js +86 -1
|
@@ -0,0 +1,477 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// P-WB-DRAFTS-R4 — WB-005 草稿与附件隔离的真实 UI 收尾验收(第四次派发)。
|
|
3
|
+
//
|
|
4
|
+
// 前三次从未通过(报告 hangRuling:最后一次打印了全部 PASS 但进程不退出,
|
|
5
|
+
// 判 HUNG;更早两次分别是宿主重启后的侧栏竞态与 state 全局竞态,一次是
|
|
6
|
+
// 驱动对项目级草稿的错误预期)。本入口相对旧驱动的变化,全部是驱动侧:
|
|
7
|
+
// 1. 退出纪律:verdict 打印后先等 CDP websocket 的 close 事件(至多
|
|
8
|
+
// 1.5s),随后无条件强制 process.exit —— 旧驱动只设 exitCode,长命
|
|
9
|
+
// 句柄(CDP websocket close 握手未完成)把事件循环拖住,这就是三挂
|
|
10
|
+
// 的根因类别(hangRuling 认可 force-exit after the verdict)。
|
|
11
|
+
// 2. 整探针 watchdog(非 unref,450s):超时写 checkpoint 证据后强制
|
|
12
|
+
// exit 3,绝不无限等待;每个子步骤再套独立预算,超时抛 STEP TIMEOUT。
|
|
13
|
+
// 3. Page.reload / 宿主重启之后,先等侧栏真实渲染出两个项目行、产品
|
|
14
|
+
// state.projects 就绪,再点击(旧 08:14/08:17 竞态的根修)。
|
|
15
|
+
// 4. 先记录 source/pinned/served 三份 UI 哈希与进程/数据身份,served
|
|
16
|
+
// 与磁盘不一致即 BLOCKED。
|
|
17
|
+
// 5. 草稿文本按派发原文:A=1111、B=2222;会话二独立草稿 1111-two。
|
|
18
|
+
// 6. 恢复预期按产品真实生命周期(apps/agent-terminal/app.js):
|
|
19
|
+
// 文本草稿走 localStorage(切换/刷新/重启都恢复);首个会话创建时
|
|
20
|
+
// 项目级草稿迁入该会话、项目级留空墓碑;附件字节只进页面内存
|
|
21
|
+
// (切换/返回恢复,刷新/重启后按设计消失),且永不进入存储。
|
|
22
|
+
// 不调用 store API 代替 UI 行为;不发送任何模型请求(1111/2222 绝不出现在
|
|
23
|
+
// 任何模型请求里);不动安装模块,只重启本用例自有隔离宿主。
|
|
24
|
+
//
|
|
25
|
+
// 退出码:0 = 全部证明;3 = 诚实 BLOCKED/超时;1 = 脚本错误。
|
|
26
|
+
const fs = require('node:fs');
|
|
27
|
+
const path = require('node:path');
|
|
28
|
+
const crypto = require('node:crypto');
|
|
29
|
+
const fixture = require('./helpers/parallel-workbench-fixture');
|
|
30
|
+
const harness = require('./helpers/parallel-workbench-runtime-harness');
|
|
31
|
+
|
|
32
|
+
const DRAFT_A = '1111';
|
|
33
|
+
const DRAFT_B = '2222';
|
|
34
|
+
const DRAFT_S2 = '1111-two';
|
|
35
|
+
const PROFILE_ID = String(process.env.PK_WB_MODEL_PROFILE || 'minimax');
|
|
36
|
+
const REQUESTED_MODEL = String(process.env.PK_WB_MODEL_ID || 'MiniMax-M3.1-Flash');
|
|
37
|
+
const LOCKED_VERSION = '0.13.6';
|
|
38
|
+
|
|
39
|
+
const KB_ROOT = path.resolve(__dirname, '..', '..');
|
|
40
|
+
const EVIDENCE_DIR = path.join(KB_ROOT, 'qa-autopilot', 'artifacts', 'parallel-20261023', 'workbench-drafts-r4');
|
|
41
|
+
const PROBE_TIMEOUT_MS = Number(process.env.PK_WB_DRAFTS_R4_TIMEOUT_MS || 450000);
|
|
42
|
+
|
|
43
|
+
const results = [];
|
|
44
|
+
const stepTimings = [];
|
|
45
|
+
function record(caseId, status, detail) {
|
|
46
|
+
results.push({ caseId, status, detail });
|
|
47
|
+
console.log(`CASE ${caseId} ${status} ${JSON.stringify(detail).slice(0, 300)}`);
|
|
48
|
+
}
|
|
49
|
+
function assertTrue(condition, message) { if (!condition) throw new Error(message); }
|
|
50
|
+
|
|
51
|
+
// 每步骤独立预算:waitUntil 自身的超时管“条件迟迟不满足”,预算管
|
|
52
|
+
// “evaluate/fetch 本身挂死”这类 waitUntil 管不到的等待。
|
|
53
|
+
async function withBudget(label, budgetMs, fn) {
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
let timer = null;
|
|
56
|
+
try {
|
|
57
|
+
const value = await Promise.race([
|
|
58
|
+
fn(),
|
|
59
|
+
new Promise((_, reject) => {
|
|
60
|
+
timer = setTimeout(() => reject(new Error(`STEP TIMEOUT: ${label} exceeded its ${budgetMs}ms budget`)), budgetMs);
|
|
61
|
+
}),
|
|
62
|
+
]);
|
|
63
|
+
stepTimings.push({ step: label, ms: Date.now() - started, outcome: 'ok' });
|
|
64
|
+
return value;
|
|
65
|
+
} catch (error) {
|
|
66
|
+
stepTimings.push({ step: label, ms: Date.now() - started, outcome: String(error && error.message || error).slice(0, 200) });
|
|
67
|
+
throw error;
|
|
68
|
+
} finally {
|
|
69
|
+
if (timer) clearTimeout(timer);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function sha256Text(text) { return crypto.createHash('sha256').update(text, 'utf8').digest('hex'); }
|
|
74
|
+
|
|
75
|
+
async function waitSidebarProjects(browser, count) {
|
|
76
|
+
return harness.waitUntil(async () => {
|
|
77
|
+
const ids = await browser.evaluate("Array.from(document.querySelectorAll('#project-list .proj')).map(node => node.dataset.project)");
|
|
78
|
+
return ids.length === count ? ids : null;
|
|
79
|
+
}, `the sidebar to list ${count} projects`, 30000);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// 等产品自己的 input 处理器把草稿写进它自己的 localStorage 键(只读旁观,
|
|
83
|
+
// 不代写):证明持久化发生在产品侧,后续的切换/刷新/重启恢复才是产品行为。
|
|
84
|
+
async function waitStorageDraft(browser, projectId, sessionId, text) {
|
|
85
|
+
const key = JSON.stringify([projectId, sessionId || null]);
|
|
86
|
+
return harness.waitUntil(async () => {
|
|
87
|
+
const storage = await harness.readDraftStorage(browser);
|
|
88
|
+
return storage.parsed && Object.prototype.hasOwnProperty.call(storage.parsed, key) && storage.parsed[key] === text;
|
|
89
|
+
}, `the product to persist its own draft ${key} as ${JSON.stringify(text)}`, 15000);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// 挂起/失败归因快照:网络(宿主健康)、DOM(页面就绪度)、服务(进程存活)。
|
|
93
|
+
async function diagnose(host, browser) {
|
|
94
|
+
const out = { at: new Date().toISOString() };
|
|
95
|
+
if (host && host.base) {
|
|
96
|
+
try {
|
|
97
|
+
const health = await harness.getJson(`${host.base}${harness.API_BASE}/health`);
|
|
98
|
+
out.hostHealth = { status: health.status, ok: health.ok, body: health.body };
|
|
99
|
+
} catch (error) { out.hostHealth = { error: String(error && error.message || error).slice(0, 160) }; }
|
|
100
|
+
if (host.child && host.child.child) {
|
|
101
|
+
out.hostPid = host.child.child.pid;
|
|
102
|
+
out.hostPidAlive = harness.listProcesses().some(entry => entry.pid === host.child.child.pid);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (browser) {
|
|
106
|
+
try {
|
|
107
|
+
out.page = await browser.evaluate("({ readyState: document.readyState, hasInput: !!document.getElementById('chat-input'), stateDefined: typeof state !== 'undefined' && !!state, sidebarProjects: document.querySelectorAll('#project-list .proj').length, composer: (document.getElementById('chat-input') || {}).value || '' })");
|
|
108
|
+
} catch (error) { out.page = { error: String(error && error.message || error).slice(0, 200) }; }
|
|
109
|
+
}
|
|
110
|
+
return out;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
(async () => {
|
|
114
|
+
const startedAt = new Date().toISOString();
|
|
115
|
+
fs.mkdirSync(path.join(EVIDENCE_DIR, 'evidence'), { recursive: true });
|
|
116
|
+
const realProfilesBefore = fixture.digestDirectory(fixture.realWorkbenchProfileDir());
|
|
117
|
+
|
|
118
|
+
// 整探针 watchdog:非 unref —— 它既保证“永不无限等待”(到点强制退),
|
|
119
|
+
// 也保证被挂住的 await 之外事件循环仍有心跳可触发它。
|
|
120
|
+
let watchdogCleared = false;
|
|
121
|
+
const watchdog = setTimeout(() => {
|
|
122
|
+
const target = path.join(EVIDENCE_DIR, 'evidence', 'drafts-r4-watchdog.json');
|
|
123
|
+
try {
|
|
124
|
+
fs.writeFileSync(target, `${JSON.stringify({
|
|
125
|
+
probe: 'parallel-workbench-drafts-r4-probe', firedAt: new Date().toISOString(), startedAt,
|
|
126
|
+
verdict: 'WATCHDOG TIMEOUT', exitCode: 3, steps: stepTimings, cases: results,
|
|
127
|
+
}, null, 2)}\n`);
|
|
128
|
+
} catch { /* best effort */ }
|
|
129
|
+
console.log(`WATCHDOG TIMEOUT after ${PROBE_TIMEOUT_MS}ms — checkpoint at ${target}; forcing exit 3`);
|
|
130
|
+
process.exit(3);
|
|
131
|
+
}, PROBE_TIMEOUT_MS);
|
|
132
|
+
|
|
133
|
+
let host = null;
|
|
134
|
+
let browser = null;
|
|
135
|
+
let opened = null;
|
|
136
|
+
let identity = null;
|
|
137
|
+
let sceneKept = null;
|
|
138
|
+
let bDetail = null;
|
|
139
|
+
let cDetail = null;
|
|
140
|
+
let dDetail = null;
|
|
141
|
+
let eDetail = null;
|
|
142
|
+
let fDetail = null;
|
|
143
|
+
let gDetail = null;
|
|
144
|
+
|
|
145
|
+
try {
|
|
146
|
+
host = await withBudget('start-host', 90000, () => harness.startHost({ prefix: 'parallel-wb-drafts-r4' }));
|
|
147
|
+
opened = await withBudget('open-browser', 90000, () => harness.openBrowser(host.base, host.layout));
|
|
148
|
+
browser = opened.browser;
|
|
149
|
+
identity = harness.moduleIdentity(host.moduleRoot);
|
|
150
|
+
assertTrue(identity.version === LOCKED_VERSION, `the hosted module is ${identity.version}, the case requires the locked ${LOCKED_VERSION}`);
|
|
151
|
+
|
|
152
|
+
// --- a. 真实宿主/浏览器身份:source(pinned disk) vs served 哈希一致 ----
|
|
153
|
+
const health = await harness.getJson(`${host.base}${harness.API_BASE}/health`);
|
|
154
|
+
assertTrue(health.ok && health.body && health.body.status === 'ok', 'the isolated host is not healthy');
|
|
155
|
+
const servedFiles = {};
|
|
156
|
+
for (const rel of ['app.js', 'index.html']) {
|
|
157
|
+
const response = await fetch(`${host.base}/agent-terminal/${rel}`, { signal: AbortSignal.timeout(10000) });
|
|
158
|
+
const text = await response.text();
|
|
159
|
+
servedFiles[rel] = {
|
|
160
|
+
httpStatus: response.status,
|
|
161
|
+
servedSha256: sha256Text(text),
|
|
162
|
+
diskSha256: harness.sha256File(path.join(host.moduleRoot, 'apps', 'agent-terminal', rel)),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
const servedMatches = Object.values(servedFiles).every(file => file.httpStatus === 200 && file.servedSha256 && file.servedSha256 === file.diskSha256);
|
|
166
|
+
assertTrue(servedMatches, 'the served agent-terminal UI is not byte-identical to the hosted module files');
|
|
167
|
+
|
|
168
|
+
const projectA = await withBudget('create-project-a', 60000, () => harness.ensureProject(browser, path.join(host.layout.root, 'r4-project-a'), { name: 'r4-project-a' }));
|
|
169
|
+
const projectB = await withBudget('create-project-b', 60000, () => harness.ensureProject(browser, path.join(host.layout.root, 'r4-project-b'), { name: 'r4-project-b' }));
|
|
170
|
+
assertTrue(projectA.created === true && projectB.created === true, 'the two projects were not created through the product form');
|
|
171
|
+
assertTrue(projectA.projectId && projectB.projectId && projectA.projectId !== projectB.projectId, 'the two projects do not have distinct ids');
|
|
172
|
+
record('WB005-R4.a-real-browser-and-host', 'PASS', {
|
|
173
|
+
browser: 'real Chrome via CDP (headless), isolated user-data-dir below the isolated layout',
|
|
174
|
+
chrome: opened.chrome,
|
|
175
|
+
module: identity,
|
|
176
|
+
servedUiIntegrity: { checked: Object.keys(servedFiles), servedEqualsDisk: servedMatches, files: servedFiles },
|
|
177
|
+
host: { mode: 'standalone', pid: host.child.child.pid, port: host.port, dataDir: host.layout.dataDir, workspace: host.layout.workspace, tempRoot: path.dirname(host.layout.root) },
|
|
178
|
+
projects: [
|
|
179
|
+
{ id: projectA.projectId, name: projectA.name, createdThroughTheProductForm: true },
|
|
180
|
+
{ id: projectB.projectId, name: projectB.name, createdThroughTheProductForm: true },
|
|
181
|
+
],
|
|
182
|
+
health: health.body,
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// 只选模型让产品具备建会话条件;从不发送消息,见 g 项证据。
|
|
186
|
+
const profiles = await harness.getJson(`${host.base}${harness.API_BASE}/profiles`);
|
|
187
|
+
const listed = Array.isArray(profiles.body && profiles.body.profiles) ? profiles.body.profiles : [];
|
|
188
|
+
const profile = listed.find(item => item.id === PROFILE_ID) || null;
|
|
189
|
+
assertTrue(profile, `the ${PROFILE_ID} profile is not visible through the read-only facade`);
|
|
190
|
+
await withBudget('select-model', 60000, () => harness.selectModel(browser, profile.name, REQUESTED_MODEL));
|
|
191
|
+
|
|
192
|
+
// --- b. 项目级草稿:A=1111、B=2222,产品侧边栏切换各自恢复 ------------
|
|
193
|
+
await withBudget('project-drafts', 90000, async () => {
|
|
194
|
+
await harness.selectProject(browser, projectA.projectId);
|
|
195
|
+
await harness.typeText(browser, DRAFT_A);
|
|
196
|
+
await waitStorageDraft(browser, projectA.projectId, null, DRAFT_A);
|
|
197
|
+
await harness.selectProject(browser, projectB.projectId);
|
|
198
|
+
const firstEntryB = await harness.readState(browser);
|
|
199
|
+
assertTrue(firstEntryB.inputValue === '', `project B must start with an empty composer, saw ${JSON.stringify(firstEntryB.inputValue)}`);
|
|
200
|
+
await harness.typeText(browser, DRAFT_B);
|
|
201
|
+
await waitStorageDraft(browser, projectB.projectId, null, DRAFT_B);
|
|
202
|
+
await harness.selectProject(browser, projectA.projectId);
|
|
203
|
+
const backInA = await harness.readState(browser);
|
|
204
|
+
assertTrue(backInA.inputValue === DRAFT_A, `project A did not restore its draft: ${JSON.stringify(backInA.inputValue)}`);
|
|
205
|
+
await harness.selectProject(browser, projectB.projectId);
|
|
206
|
+
const backInB = await harness.readState(browser);
|
|
207
|
+
assertTrue(backInB.inputValue === DRAFT_B, `project B did not restore its draft: ${JSON.stringify(backInB.inputValue)}`);
|
|
208
|
+
assertTrue(!backInA.inputValue.includes(DRAFT_B) && !backInB.inputValue.includes(DRAFT_A), 'a project draft leaked across projects');
|
|
209
|
+
bDetail = {
|
|
210
|
+
switch: "the product's own sidebar project head (.proj-item), a real click",
|
|
211
|
+
projectA: { id: projectA.projectId, draft: DRAFT_A, composerAfterSwitchBack: backInA.inputValue },
|
|
212
|
+
projectB: { id: projectB.projectId, draft: DRAFT_B, composerOnFirstEntry: firstEntryB.inputValue, composerAfterSwitchBack: backInB.inputValue },
|
|
213
|
+
crossLeak: backInA.inputValue.includes(DRAFT_B) || backInB.inputValue.includes(DRAFT_A),
|
|
214
|
+
persistedByTheProduct: true,
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
record('WB005-R4.b-project-drafts-are-isolated', 'PASS', bDetail);
|
|
218
|
+
|
|
219
|
+
// --- c. 真实浏览器刷新后项目级草稿恢复(此时还没有任何会话)-----------
|
|
220
|
+
await withBudget('refresh-project-drafts', 60000, async () => {
|
|
221
|
+
await harness.reloadPage(browser);
|
|
222
|
+
await waitSidebarProjects(browser, 2);
|
|
223
|
+
await harness.selectProject(browser, projectA.projectId);
|
|
224
|
+
const aAfter = await harness.readState(browser);
|
|
225
|
+
assertTrue(aAfter.inputValue === DRAFT_A, `project A draft lost after refresh: ${JSON.stringify(aAfter.inputValue)}`);
|
|
226
|
+
await harness.selectProject(browser, projectB.projectId);
|
|
227
|
+
const bAfter = await harness.readState(browser);
|
|
228
|
+
assertTrue(bAfter.inputValue === DRAFT_B, `project B draft lost after refresh: ${JSON.stringify(bAfter.inputValue)}`);
|
|
229
|
+
cDetail = {
|
|
230
|
+
refresh: 'a real Page.reload; the sidebar re-rendered both projects before any click',
|
|
231
|
+
composerInProjectAAfterRefresh: aAfter.inputValue,
|
|
232
|
+
composerInProjectBAfterRefresh: bAfter.inputValue,
|
|
233
|
+
storageKeysAfterRefresh: (await harness.readDraftStorage(browser)).keys,
|
|
234
|
+
};
|
|
235
|
+
});
|
|
236
|
+
record('WB005-R4.c-drafts-survive-a-real-browser-refresh', 'PASS', cDetail);
|
|
237
|
+
|
|
238
|
+
// --- d. 同一项目两个会话的草稿隔离 -------------------------------------
|
|
239
|
+
let sessionS1 = null;
|
|
240
|
+
let sessionS2 = null;
|
|
241
|
+
await withBudget('session-drafts', 120000, async () => {
|
|
242
|
+
await harness.selectProject(browser, projectA.projectId);
|
|
243
|
+
await harness.clickNewSession(browser);
|
|
244
|
+
const s1State = await harness.waitForState(browser, state => state.product && state.product.activeSessionId, 'the first session of project A', 30000);
|
|
245
|
+
sessionS1 = s1State.product.activeSessionId;
|
|
246
|
+
// 首会话创建时产品把项目级草稿 1111 迁入该会话(app.js newSession)。
|
|
247
|
+
const inS1 = await harness.readState(browser);
|
|
248
|
+
assertTrue(inS1.inputValue === DRAFT_A, `the project draft did not migrate into the first session: ${JSON.stringify(inS1.inputValue)}`);
|
|
249
|
+
const tombstone = await harness.readDraftStorage(browser);
|
|
250
|
+
const tombstoneKey = JSON.stringify([projectA.projectId, null]);
|
|
251
|
+
assertTrue(tombstone.parsed && tombstone.parsed[tombstoneKey] === '', 'the project-level entry must be an empty migration tombstone after the first session');
|
|
252
|
+
|
|
253
|
+
await harness.clickNewSession(browser);
|
|
254
|
+
const s2State = await harness.waitForState(browser, state => state.product && state.product.activeSessionId && state.product.activeSessionId !== sessionS1, 'the second session of project A', 30000);
|
|
255
|
+
sessionS2 = s2State.product.activeSessionId;
|
|
256
|
+
const s2Fresh = await harness.readState(browser);
|
|
257
|
+
assertTrue(s2Fresh.inputValue === '', `session two must start empty, saw ${JSON.stringify(s2Fresh.inputValue)}`);
|
|
258
|
+
await harness.typeText(browser, DRAFT_S2);
|
|
259
|
+
await waitStorageDraft(browser, projectA.projectId, sessionS2, DRAFT_S2);
|
|
260
|
+
|
|
261
|
+
await harness.openSessionRow(browser, projectA.projectId, sessionS1);
|
|
262
|
+
const backInS1 = await harness.readState(browser);
|
|
263
|
+
assertTrue(backInS1.inputValue === DRAFT_A, `session one draft not restored: ${JSON.stringify(backInS1.inputValue)}`);
|
|
264
|
+
assertTrue(!backInS1.inputValue.includes(DRAFT_S2), 'session two draft leaked into session one');
|
|
265
|
+
await harness.openSessionRow(browser, projectA.projectId, sessionS2);
|
|
266
|
+
const backInS2 = await harness.readState(browser);
|
|
267
|
+
assertTrue(backInS2.inputValue === DRAFT_S2, `session two draft not restored: ${JSON.stringify(backInS2.inputValue)}`);
|
|
268
|
+
assertTrue(backInS2.inputValue !== DRAFT_A, 'session two must not hold session one draft (exact equality)');
|
|
269
|
+
dDetail = {
|
|
270
|
+
switch: "the product's own sidebar session row (.session), real clicks",
|
|
271
|
+
projectId: projectA.projectId,
|
|
272
|
+
migrationIntoFirstSession: { sessionId: sessionS1, composerAfterCreate: inS1.inputValue, projectLevelTombstone: true },
|
|
273
|
+
sessionOne: { sessionId: sessionS1, draft: DRAFT_A, composerAfterReopen: backInS1.inputValue },
|
|
274
|
+
sessionTwo: { sessionId: sessionS2, draft: DRAFT_S2, composerOnCreate: s2Fresh.inputValue, composerAfterReopen: backInS2.inputValue },
|
|
275
|
+
sessionOneDraftLeakedIntoSessionTwo: s2Fresh.inputValue !== '',
|
|
276
|
+
sessionTwoDraftLeakedIntoSessionOne: backInS1.inputValue === DRAFT_S2,
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
record('WB005-R4.d-session-drafts-are-isolated', 'PASS', dDetail);
|
|
280
|
+
|
|
281
|
+
// --- e. 附件生命周期与跨项目隔离 ---------------------------------------
|
|
282
|
+
await withBudget('attachments', 120000, async () => {
|
|
283
|
+
await harness.openSessionRow(browser, projectA.projectId, sessionS1);
|
|
284
|
+
const tokenA = `R4-ATTACH-A-${crypto.randomBytes(4).toString('hex')}`;
|
|
285
|
+
const contentA = `${tokenA}\nP-WB-DRAFTS-R4 attachment of project A session one\n`;
|
|
286
|
+
await harness.attachFile(browser, 'r4-note.txt', contentA);
|
|
287
|
+
const s1WithAttachment = await harness.readState(browser);
|
|
288
|
+
assertTrue(s1WithAttachment.attachments.length === 1 && s1WithAttachment.attachments[0].includes('r4-note.txt'), 'the attachment did not reach the tray of session one');
|
|
289
|
+
assertTrue(s1WithAttachment.product.attachmentCount === 1, 'the product did not count the attachment');
|
|
290
|
+
const base64A = Buffer.from(contentA, 'utf8').toString('base64');
|
|
291
|
+
const storageWithA = await harness.readDraftStorage(browser);
|
|
292
|
+
const bytesAInStorage = storageWithA.raw.includes(tokenA) || storageWithA.raw.includes(base64A);
|
|
293
|
+
|
|
294
|
+
await harness.selectProject(browser, projectB.projectId);
|
|
295
|
+
const trayInB = await harness.readState(browser);
|
|
296
|
+
assertTrue(trayInB.attachments.length === 0 && trayInB.product.attachmentCount === 0, "A's attachment leaked into project B");
|
|
297
|
+
|
|
298
|
+
const tokenB = `R4-ATTACH-B-${crypto.randomBytes(4).toString('hex')}`;
|
|
299
|
+
const contentB = `${tokenB}\nP-WB-DRAFTS-R4 attachment of project B\n`;
|
|
300
|
+
await harness.attachFile(browser, 'r4-b.txt', contentB);
|
|
301
|
+
const bWithAttachment = await harness.readState(browser);
|
|
302
|
+
assertTrue(bWithAttachment.attachments.length === 1 && bWithAttachment.attachments[0].includes('r4-b.txt'), 'the attachment of project B did not reach its tray');
|
|
303
|
+
const base64B = Buffer.from(contentB, 'utf8').toString('base64');
|
|
304
|
+
const storageWithB = await harness.readDraftStorage(browser);
|
|
305
|
+
const bytesBInStorage = storageWithB.raw.includes(tokenB) || storageWithB.raw.includes(base64B);
|
|
306
|
+
assertTrue(!bytesAInStorage && !bytesBInStorage, 'attachment bytes entered the browser storage');
|
|
307
|
+
|
|
308
|
+
await harness.openSessionRow(browser, projectA.projectId, sessionS1);
|
|
309
|
+
const backInS1 = await harness.readState(browser);
|
|
310
|
+
assertTrue(backInS1.attachments.length === 1 && backInS1.attachments[0].includes('r4-note.txt'), "session one's attachment did not come back");
|
|
311
|
+
assertTrue(!backInS1.attachments.join(' ').includes('r4-b.txt'), "B's attachment leaked into A's session");
|
|
312
|
+
eDetail = {
|
|
313
|
+
attach: "the product's own <input type=\"file\"> change handler (a real File into the real input)",
|
|
314
|
+
sessionOne: { sessionId: sessionS1, file: 'r4-note.txt', tray: s1WithAttachment.attachments, productAttachmentCount: s1WithAttachment.product.attachmentCount, trayAfterReturn: backInS1.attachments },
|
|
315
|
+
projectB: { file: 'r4-b.txt', trayWhenInA: trayInB.attachments, ownTray: bWithAttachment.attachments },
|
|
316
|
+
attachmentBytesInBrowserStorage: bytesAInStorage || bytesBInStorage,
|
|
317
|
+
storageKeys: storageWithB.keys,
|
|
318
|
+
contract: 'app.js writeDraft(): only the text is persisted, attachment bytes stay in page memory',
|
|
319
|
+
};
|
|
320
|
+
});
|
|
321
|
+
record('WB005-R4.e-attachment-lifecycle-and-isolation', 'PASS', eDetail);
|
|
322
|
+
|
|
323
|
+
// --- f. 只重启本用例自己的隔离宿主(同布局/同端口/同浏览器 profile)----
|
|
324
|
+
await withBudget('own-host-restart', 180000, async () => {
|
|
325
|
+
const oldPid = host.child.child.pid;
|
|
326
|
+
const oldPort = host.port;
|
|
327
|
+
await harness.stopHost(host);
|
|
328
|
+
const exitInfo = await host.child.exited;
|
|
329
|
+
const oldGone = !harness.listProcesses().some(entry => entry.pid === oldPid);
|
|
330
|
+
assertTrue(oldGone && Boolean(exitInfo), 'the own host did not really exit');
|
|
331
|
+
|
|
332
|
+
const restarted = await harness.startHost({ layout: host.layout, port: oldPort });
|
|
333
|
+
host = restarted;
|
|
334
|
+
const identityAfter = harness.moduleIdentity(restarted.moduleRoot);
|
|
335
|
+
assertTrue(identityAfter.version === LOCKED_VERSION && identityAfter.uiFiles['apps/agent-terminal/app.js'] === identity.uiFiles['apps/agent-terminal/app.js'], 'the restarted host serves different UI bytes');
|
|
336
|
+
const healthAfter = await harness.getJson(`${restarted.base}${harness.API_BASE}/health`);
|
|
337
|
+
assertTrue(healthAfter.ok && healthAfter.body && healthAfter.body.status === 'ok', 'the restarted host is not healthy');
|
|
338
|
+
|
|
339
|
+
await harness.reloadPage(browser);
|
|
340
|
+
await waitSidebarProjects(browser, 2);
|
|
341
|
+
const stateAfterRestart = await harness.waitForState(browser, state => state.product && state.product.projects.length === 2, 'both projects after the restart', 30000);
|
|
342
|
+
|
|
343
|
+
await harness.selectProject(browser, projectB.projectId);
|
|
344
|
+
const bAfter = await harness.readState(browser);
|
|
345
|
+
assertTrue(bAfter.inputValue === DRAFT_B, `project B draft lost after the own-host restart: ${JSON.stringify(bAfter.inputValue)}`);
|
|
346
|
+
assertTrue(bAfter.attachments.length === 0, 'a memory-backed attachment survived the restart or leaked into B');
|
|
347
|
+
|
|
348
|
+
await harness.selectProject(browser, projectA.projectId);
|
|
349
|
+
const aProjectAfter = await harness.readState(browser);
|
|
350
|
+
assertTrue(aProjectAfter.inputValue === '', `project A project-level entry must stay the migration tombstone, saw ${JSON.stringify(aProjectAfter.inputValue)}`);
|
|
351
|
+
await harness.openSessionRow(browser, projectA.projectId, sessionS1);
|
|
352
|
+
const s1After = await harness.readState(browser);
|
|
353
|
+
assertTrue(s1After.inputValue === DRAFT_A, `session one draft lost after the restart: ${JSON.stringify(s1After.inputValue)}`);
|
|
354
|
+
await harness.openSessionRow(browser, projectA.projectId, sessionS2);
|
|
355
|
+
const s2After = await harness.readState(browser);
|
|
356
|
+
assertTrue(s2After.inputValue === DRAFT_S2, `session two draft lost after the restart: ${JSON.stringify(s2After.inputValue)}`);
|
|
357
|
+
|
|
358
|
+
const storageFinal = await harness.readDraftStorage(browser);
|
|
359
|
+
fDetail = {
|
|
360
|
+
restart: "only this case's own isolated host child was stopped and restarted (same layout, same port, same browser profile)",
|
|
361
|
+
oldHostPid: oldPid, oldHostExited: true, oldHostProcessStillListed: !oldGone, oldHostExitCode: exitInfo && exitInfo.code,
|
|
362
|
+
newHostPid: restarted.child.child.pid, portKept: oldPort === restarted.port,
|
|
363
|
+
healthAfterRestart: healthAfter.body,
|
|
364
|
+
projectsAfterRestart: stateAfterRestart.product.projects.map(project => ({ id: project.id, name: project.name })),
|
|
365
|
+
composerInProjectBAfterRestart: bAfter.inputValue,
|
|
366
|
+
attachmentTrayInProjectBAfterRestart: bAfter.attachments,
|
|
367
|
+
projectAProjectLevelAfterRestart: aProjectAfter.inputValue,
|
|
368
|
+
projectAProjectLevelNote: 'the empty value is the migration tombstone the product itself wrote; the draft lives in session one',
|
|
369
|
+
composerInSessionOneAfterRestart: s1After.inputValue,
|
|
370
|
+
composerInSessionTwoAfterRestart: s2After.inputValue,
|
|
371
|
+
storageKeysAfterRestart: storageFinal.keys,
|
|
372
|
+
};
|
|
373
|
+
});
|
|
374
|
+
record('WB005-R4.f-own-host-restart-keeps-projects-and-drafts', 'PASS', fDetail);
|
|
375
|
+
|
|
376
|
+
// --- g. 全程零模型请求 -------------------------------------------------
|
|
377
|
+
await withBudget('no-model-request', 30000, async () => {
|
|
378
|
+
const events = await harness.recordedEvents(browser);
|
|
379
|
+
const modelEvents = events.filter(event => event.type === 'claude/result' || event.type === 'claude/init' || event.type === 'claude/user-prompt');
|
|
380
|
+
assertTrue(modelEvents.length === 0, `the draft case triggered model stream events: ${JSON.stringify(modelEvents.map(event => event.type))}`);
|
|
381
|
+
gDetail = { recordedStreamEvents: events.map(event => event.type), modelStreamEvents: [], draftsNeverSentToAnyModel: [DRAFT_A, DRAFT_B, DRAFT_S2], paidTurns: 0 };
|
|
382
|
+
});
|
|
383
|
+
record('WB005-R4.g-no-model-request-was-made', 'PASS', gDetail);
|
|
384
|
+
} catch (error) {
|
|
385
|
+
const diagnosis = await diagnose(host, browser).catch(() => null);
|
|
386
|
+
record('WB005-R4.runtime', 'BLOCKED', { error: String(error && error.message || error), diagnosis, stepsSoFar: stepTimings.slice() });
|
|
387
|
+
sceneKept = host ? host.layout.root : null;
|
|
388
|
+
} finally {
|
|
389
|
+
// 先关浏览器(内部会杀 Chrome 树并清 profile),再显式等 CDP websocket
|
|
390
|
+
// 的 close 事件(至多 1.5s)——旧驱动不等这一步,close 握手未完成的长命
|
|
391
|
+
// socket 拖住事件循环,进程永不退出。
|
|
392
|
+
if (browser) {
|
|
393
|
+
try { await browser.close(); } catch { /* disposable */ }
|
|
394
|
+
try {
|
|
395
|
+
await Promise.race([
|
|
396
|
+
new Promise(resolve => { try { browser.socket.once('close', resolve); } catch { resolve(); } }),
|
|
397
|
+
new Promise(resolve => setTimeout(resolve, 1500)),
|
|
398
|
+
]);
|
|
399
|
+
} catch { /* best effort */ }
|
|
400
|
+
}
|
|
401
|
+
try { if (host && host.child) await harness.stopHost(host); } catch { /* best effort */ }
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// 宿主已停(只读门面本就不写),对比真实 profile 目录字节级不变。
|
|
405
|
+
const digestComparison = fixture.compareDigests(realProfilesBefore, fixture.digestDirectory(fixture.realWorkbenchProfileDir()));
|
|
406
|
+
record('WB005-R4.h-real-profiles-byte-identical', digestComparison.byteIdentical ? 'PASS' : 'FAIL', {
|
|
407
|
+
profileDir: fixture.realWorkbenchProfileDir(),
|
|
408
|
+
comparison: 'byte-level SHA256, computed in memory; digests never printed, logged or persisted',
|
|
409
|
+
fileCount: digestComparison.count,
|
|
410
|
+
changedFiles: digestComparison.changedFiles,
|
|
411
|
+
addedFiles: digestComparison.addedFiles,
|
|
412
|
+
removedFiles: digestComparison.removedFiles,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
watchdogCleared = true;
|
|
416
|
+
clearTimeout(watchdog);
|
|
417
|
+
|
|
418
|
+
const essential = [
|
|
419
|
+
'WB005-R4.a-real-browser-and-host',
|
|
420
|
+
'WB005-R4.b-project-drafts-are-isolated',
|
|
421
|
+
'WB005-R4.c-drafts-survive-a-real-browser-refresh',
|
|
422
|
+
'WB005-R4.d-session-drafts-are-isolated',
|
|
423
|
+
'WB005-R4.e-attachment-lifecycle-and-isolation',
|
|
424
|
+
'WB005-R4.f-own-host-restart-keeps-projects-and-drafts',
|
|
425
|
+
'WB005-R4.g-no-model-request-was-made',
|
|
426
|
+
'WB005-R4.h-real-profiles-byte-identical',
|
|
427
|
+
];
|
|
428
|
+
const proven = essential.every(id => (results.find(entry => entry.caseId === id) || {}).status === 'PASS');
|
|
429
|
+
|
|
430
|
+
const summary = {
|
|
431
|
+
lane: 'workbench-drafts-r4',
|
|
432
|
+
file: 'parallel-workbench-drafts-r4-probe.js',
|
|
433
|
+
case: 'WB-005',
|
|
434
|
+
title: '草稿与附件隔离(真实浏览器 + 真实 UI 操作,R4 收尾)',
|
|
435
|
+
startedAt,
|
|
436
|
+
finishedAt: new Date().toISOString(),
|
|
437
|
+
module: identity,
|
|
438
|
+
host: host ? { mode: 'standalone', pid: host.child.child.pid, port: host.port, dataDir: host.layout.dataDir, workspace: host.layout.workspace } : null,
|
|
439
|
+
timeouts: { wholeProbeWatchdogMs: PROBE_TIMEOUT_MS, perStepBudgets: 'withBudget labels in steps below', exitDiscipline: 'graceful CDP close wait (<=1.5s) then forced process.exit after the verdict' },
|
|
440
|
+
drafts: { projectA: DRAFT_A, projectB: DRAFT_B, sessionTwoOfProjectA: DRAFT_S2, sentToAnyModel: false },
|
|
441
|
+
uiActions: [
|
|
442
|
+
"the product's own add-project form to create both projects",
|
|
443
|
+
"the product's own sidebar project head (.proj-item) to switch projects",
|
|
444
|
+
"the product's own sidebar session row (.session) to open sessions",
|
|
445
|
+
"the product's own 新会话 button to create sessions",
|
|
446
|
+
"the product's own <input type=\"file\"> change handler to attach files",
|
|
447
|
+
'a real Page.reload of the real page (twice: refresh case and after the own-host restart)',
|
|
448
|
+
'a real stop+start of only this case\'s own isolated host child',
|
|
449
|
+
],
|
|
450
|
+
storeApiUsedAsUiSubstitute: false,
|
|
451
|
+
recoveryExpectationsFollowTheProductLifecycle: 'text drafts are storage-backed and must survive switch/refresh/restart; the first session migrates the project-level draft and leaves a tombstone; attachments are page-memory only and must vanish on refresh/restart without ever entering storage',
|
|
452
|
+
steps: stepTimings,
|
|
453
|
+
cases: results,
|
|
454
|
+
verdict: proven
|
|
455
|
+
? 'PASS: 草稿按项目/会话隔离并在切换/刷新/自有宿主重启后分别恢复;附件按会话生命周期不跨项目泄漏且字节永不入存储;全程零模型请求;进程真实退出(exit code 由运行方观测)'
|
|
456
|
+
: 'BLOCKED',
|
|
457
|
+
paidTurnsSent: 0,
|
|
458
|
+
quotaEndpointQueried: false,
|
|
459
|
+
sceneKeptOnFailure: sceneKept,
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
harness.writeEvidence(path.join(EVIDENCE_DIR, 'evidence', 'drafts-r4-probe.json'), summary);
|
|
463
|
+
if (!proven) {
|
|
464
|
+
if (sceneKept) console.log(`SCENE KEPT ${sceneKept}`);
|
|
465
|
+
} else if (host) {
|
|
466
|
+
fixture.removeTree(host.layout.root);
|
|
467
|
+
}
|
|
468
|
+
console.log(`parallel-workbench-drafts-r4-probe verdict=${summary.verdict}`);
|
|
469
|
+
const exitCode = proven ? 0 : 3;
|
|
470
|
+
// 强制退出(hangRuling 认可的根修):verdict 打印后进程必须真的退。
|
|
471
|
+
setTimeout(() => process.exit(exitCode), 300);
|
|
472
|
+
process.exitCode = exitCode;
|
|
473
|
+
})().catch(error => {
|
|
474
|
+
console.error(error);
|
|
475
|
+
setTimeout(() => process.exit(1), 300);
|
|
476
|
+
process.exitCode = 1;
|
|
477
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// P-WB-DRAFTS-R5 诊断(首失败归因,不接触产品/真实安装):
|
|
3
|
+
// 第一次 R5 复测在 open-browser 阻塞——Chrome 以隔离 env 启动后拒绝开放
|
|
4
|
+
// remote debugging(stderr: "DevTools remote debugging requires a non-default
|
|
5
|
+
// data directory" / "Can't retrieve app data directory"),DevToolsActivePort
|
|
6
|
+
// 一直不出现。本脚本用与 cdp-browser 完全相同的 flag 逐组叠加隔离变量,
|
|
7
|
+
// 找出导致该拒绝的具体环境变量。每组一个全新临时 profile(位于共享 temp
|
|
8
|
+
// root 下),超时 25s,结束即杀进程树并清理 profile。
|
|
9
|
+
const fs = require('node:fs');
|
|
10
|
+
const path = require('node:path');
|
|
11
|
+
const { spawn, spawnSync } = require('node:child_process');
|
|
12
|
+
const { findChromeDetailed } = require('./helpers/find-chrome');
|
|
13
|
+
|
|
14
|
+
const chrome = findChromeDetailed().path;
|
|
15
|
+
const TEMP_ROOT = 'D:/SanQian.Xu/.project-knowledge-test-temp';
|
|
16
|
+
const baseDir = fs.mkdtempSync(path.join(TEMP_ROOT, 'r5-chrome-bisect-'));
|
|
17
|
+
const parsed = path.parse(baseDir);
|
|
18
|
+
const iso = {
|
|
19
|
+
APPDATA: path.join(baseDir, 'appdata'),
|
|
20
|
+
LOCALAPPDATA: path.join(baseDir, 'localappdata'),
|
|
21
|
+
TEMP: path.join(baseDir, 'temp'),
|
|
22
|
+
TMP: path.join(baseDir, 'temp'),
|
|
23
|
+
TMPDIR: path.join(baseDir, 'temp'),
|
|
24
|
+
HOME: path.join(baseDir, 'home'),
|
|
25
|
+
USERPROFILE: path.join(baseDir, 'home'),
|
|
26
|
+
HOMEDRIVE: parsed.root,
|
|
27
|
+
HOMEPATH: baseDir.slice(parsed.root.length),
|
|
28
|
+
CODEX_HOME: path.join(baseDir, 'codex-home'),
|
|
29
|
+
CLAUDE_CONFIG_DIR: path.join(baseDir, 'claude-config'),
|
|
30
|
+
};
|
|
31
|
+
for (const dir of new Set(Object.values(iso))) {
|
|
32
|
+
if (path.resolve(dir) !== path.parse(dir).root) fs.mkdirSync(dir, { recursive: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const GROUPS = {
|
|
36
|
+
'S11-full-prefixed-appdata-elsewhere-datadir': Object.keys(iso),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)); }
|
|
40
|
+
|
|
41
|
+
async function tryScenario(name, keys, shapedDataDir = false) {
|
|
42
|
+
// S11: 预先在隔离 home 里造出 %USERPROFILE%\AppData\Local\Google\Chrome\User Data
|
|
43
|
+
// 目录结构(空),但把实际 --user-data-dir 放在别处 —— 检验 gate 是否只因
|
|
44
|
+
// default 解析失败而拒绝。
|
|
45
|
+
const defaultShaped = path.join(iso.USERPROFILE, 'AppData', 'Local', 'Google', 'Chrome', 'User Data');
|
|
46
|
+
fs.mkdirSync(defaultShaped, { recursive: true });
|
|
47
|
+
let profileDir = path.join(baseDir, `profile-${name}`);
|
|
48
|
+
if (shapedDataDir) {
|
|
49
|
+
profileDir = defaultShaped;
|
|
50
|
+
}
|
|
51
|
+
fs.rmSync(profileDir, { recursive: true, force: true });
|
|
52
|
+
fs.mkdirSync(profileDir, { recursive: true });
|
|
53
|
+
const env = { ...process.env };
|
|
54
|
+
for (const key of keys) env[key] = iso[key];
|
|
55
|
+
const stderr = [];
|
|
56
|
+
const child = spawn(chrome, [
|
|
57
|
+
'--headless=new', '--disable-gpu', '--disable-background-networking',
|
|
58
|
+
'--disable-default-apps', '--disable-extensions', '--no-first-run',
|
|
59
|
+
'--no-default-browser-check', '--remote-debugging-port=0',
|
|
60
|
+
`--user-data-dir=${profileDir}`, '--window-size=1360,900', 'about:blank',
|
|
61
|
+
], { stdio: ['ignore', 'ignore', 'pipe'], windowsHide: true, env });
|
|
62
|
+
child.stderr.on('data', chunk => { stderr.push(String(chunk)); });
|
|
63
|
+
const portFile = path.join(profileDir, 'DevToolsActivePort');
|
|
64
|
+
const deadline = Date.now() + 25000;
|
|
65
|
+
let port = null;
|
|
66
|
+
while (Date.now() < deadline && child.exitCode === null && !port) {
|
|
67
|
+
try {
|
|
68
|
+
const text = fs.readFileSync(portFile, 'utf8');
|
|
69
|
+
const parsedPort = Number.parseInt(String(text).split(/\r?\n/, 1)[0], 10);
|
|
70
|
+
if (Number.isInteger(parsedPort) && parsedPort > 0) port = parsedPort;
|
|
71
|
+
} catch { /* not yet */ }
|
|
72
|
+
if (!port) await wait(250);
|
|
73
|
+
}
|
|
74
|
+
const tail = stderr.join('').split(/\r?\n/).filter(Boolean).slice(0, 6);
|
|
75
|
+
const refused = tail.some(line => line.includes('requires a non-default data directory'));
|
|
76
|
+
try { spawnSync('taskkill', ['/PID', String(child.pid), '/T', '/F'], { stdio: 'ignore', timeout: 10000 }); } catch {}
|
|
77
|
+
await wait(500);
|
|
78
|
+
fs.rmSync(profileDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
79
|
+
return { scenario: name, isolated: keys, cdpUp: Boolean(port), port, refusalMessage: refused, exitCode: child.exitCode, stderrHead: tail };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
(async () => {
|
|
83
|
+
const out = [];
|
|
84
|
+
for (const [name, keys] of Object.entries(GROUPS)) {
|
|
85
|
+
out.push(await tryScenario(name, keys, name.endsWith('shaped-datadir')));
|
|
86
|
+
}
|
|
87
|
+
fs.rmSync(baseDir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
|
|
88
|
+
console.log(JSON.stringify(out, null, 2));
|
|
89
|
+
})();
|