/** 只读回查已有任务的文件;--save 仅保存诊断证据,不补登记或重发。 */ import fs from 'node:fs'; import path from 'node:path'; import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { recordProgress } from './lib/project-recovery.mjs'; const arg = (key, fallback) => process.argv.find(x => x.startsWith('--' + key + '='))?.slice(key.length + 3) ?? fallback; const out = path.resolve(arg('out', 'test-results/new-account-20261128')); const state = JSON.parse(fs.readFileSync(path.join(out, 'state.json'))); const account = JSON.parse(fs.readFileSync(arg('account-file', '.local-backup/new-account-20261128/account.json'))); const config = JSON.parse(fs.readFileSync('.claude/dev-login.json')); const action = state.actions[arg('action', 'trialFilesV3')]; assert.equal(account.userId, state.userId, '账号与本轮账本不一致'); assert.ok(action?.proof?.completion, '只检查已有完整回执的任务'); const headers = { 'X-Parse-Application-Id': 'ncloudmaster', 'X-Parse-Master-Key': config.masterKey }; async function get(url) { const response = await fetch(url, { headers, signal: AbortSignal.timeout(30000) }); const data = await response.json(); assert.ok(response.ok && !data.error, '只读查询失败:' + response.status); return data; } const response = await fetch('https://server.fmode.cn/api/functions', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-Parse-Application-Id': 'ncloudmaster', 'X-Parse-Session-Token': account.token }, body: JSON.stringify({ id: 'THXAOGKiPK', token: account.token, params: { action: 'listBySession', token: account.token, roomId: action.roomId, limit: 200 } }), signal: AbortSignal.timeout(30000) }); const listing = await response.json(); assert.equal(listing.code, 200, '文件接口查询失败'); const urls = [...new Set((action.proof.body.match(/https:\/\/s3\.fmode\.cn\/[^\s)<>`]+/g) || []).filter(url => action.expectedFiles.some(name => url.endsWith(name))))]; assert.equal(urls.length, action.expectedFiles.length, '回执中的成果地址数量与本轮任务不符'); const rows = []; for (const url of urls) { const recordId = new URL(url).pathname.split('/')[4]; if (recordId && !rows.some(row => row.objectId === recordId)) { const row = await get('https://server.fmode.cn/parse/classes/AgentDeliverable/' + encodeURIComponent(recordId)); rows.push({ objectId: row.objectId, userId: row.user?.objectId, owner: row.owner?.objectId, agentId: row.agentId, roomId: row.roomId, threadRoot: row.threadRoot, fileName: row.fileName, fileUrl: row.fileUrl, status: row.status, artifacts: row.artifacts, keys: Object.keys(row) }); } } const query = new URL('https://server.fmode.cn/parse/classes/AgentDeliverable'); query.searchParams.set('where', JSON.stringify({ fileUrl: { $in: urls } })); query.searchParams.set('limit', '30'); const byUrl = (await get(query)).results || []; const objects = []; for (const url of urls) { const remote = await fetch(url, { signal: AbortSignal.timeout(30000) }); const bytes = Buffer.from(await remote.arrayBuffer()); const content = bytes.toString('utf8'); const name = action.expectedFiles.find(name => url.endsWith(name)); objects.push({ name, url, http: remote.status, bytes: bytes.length, sha256: createHash('sha256').update(bytes).digest('hex'), contains: Object.fromEntries([action.marker, action.inputMarker, '2879', '179', '64'].map(x => [x, content.includes(x)])) }); if (process.argv.includes('--save')) fs.writeFileSync(path.join(out, 'readback-' + name), bytes); } const result = { at: new Date().toISOString(), owner: state.userId, agentId: state.trial.agentId, roomId: action.roomId, expectedFiles: action.expectedFiles, listed: listing.files, reportRows: rows, registrations: byUrl.map(row => ({ id: row.objectId, userId: row.user?.objectId, agentId: row.agentId, roomId: row.roomId, fileUrl: row.fileUrl, fileName: row.fileName, artifacts: row.artifacts })), objects }; if (process.argv.includes('--save')) { fs.writeFileSync(path.join(out, 'trial-files-diagnostics-20261129.json'), JSON.stringify(result, null, 2) + '\n'); recordProgress(process.cwd(), '已只读回查 V3 两份成果对象、原报告和逐 URL 登记;未补登记或重发。证据 ' + path.relative(process.cwd(), out) + '/trial-files-diagnostics-20261129.json'); } console.log(JSON.stringify({ reportRows: rows, registrations: result.registrations, objects, listedExpected: (listing.files || []).filter(x => urls.includes(x.url)) }, null, 2));