- Capabilities: all 14 registered (AO: inventory.query, download.plan/submit, organize.plan/execute,
policy.preview/apply; agent: task.inspect/retry/cancel); startup asserts count == 14.
Registry injects server-side authorize (automation_grant by action/scope/policy version/budget,
one-shot approval bound to plan id + payload hash + revision + expiry; model claims ignored;
automation switch), audit_event, server idempotency keys and a capability_invocation op ledger
(migration 0021) used for crash reconciliation. download.plan creates draft plans only;
download.submit promotes draft -> reserved after authorization.
- Agent session API: POST/GET /agent/runs, GET /agent/runs/{id} (events by seq, messages, report),
POST .../messages (wake), POST .../abort; automation-grants, approvals, capabilities invoke, tasks.
- runAgent task: Pi or fake provider from settings (apiKey via secrets), events persisted to
agent_run_event then published, resume + ledger reconciliation when pendingOperations > 0,
waits for goal-linked downloads/imports and reports from business tables (submitted != imported).
- Background triggers: decision.created -> bounded plan_only investigation (dedupe per decision);
decision.updated(resolved) -> resolveDecision executes chosen option.
- W2 closure: all OpenAPI routes registered in contracts api.ts (+ subset test); TMDB key from
settings secret_ref with env fallback; PUT /sites/{id}/credentials documented as alias of
/site-accounts; completion events documented as existing status events.
- e2e (real PG + OpenWorkflow + testkit mocks): RSS->library, agent delegation with grant/deny,
background continuation, worker kill -9 recovery (single qB add), auto investigation dedupe.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
69 lines
2.6 KiB
TypeScript
69 lines
2.6 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { createQbClient } from "@umt/adapters";
|
|
import type { FakeScript } from "@umt/agent";
|
|
import { makeTorrent } from "@umt/testkit";
|
|
import { createAcquisitionOrganizeModule } from "../../../src/modules/acquisition-organize/index.ts";
|
|
import { createAgentModule } from "../../../src/modules/agent/index.ts";
|
|
import { authSettingsModule } from "../../../src/modules/auth-settings/index.ts";
|
|
import { createSourcesIdentityModule } from "../../../src/modules/sources-identity/index.ts";
|
|
import type { ServerModule } from "../../../src/modules/types.ts";
|
|
|
|
// e2e 模块装配:真实四个模块,外部依赖指向 testkit mock(qB 账号 admin/adminadmin、固定磁盘用量、按标题生成的种子)。
|
|
// harness(API/worker 同进程)与崩溃恢复用的 worker 子进程共用这一份,保证两边行为一致。
|
|
|
|
export const TORRENT_SIZE = 300_000;
|
|
|
|
/** 按发布标题确定性地生成种子(同标题 → 同 infohash,父子进程一致) */
|
|
export function torrentFor(title: string) {
|
|
const seed = createHash("sha256").update(title).digest().readUInt32BE(0);
|
|
return makeTorrent({ name: `${title}.mkv`, length: TORRENT_SIZE, pieceSeed: seed });
|
|
}
|
|
|
|
export interface E2EModuleOptions {
|
|
sessionDir: string;
|
|
fakeScripts?: FakeScript[];
|
|
/** 下载同步周期(毫秒) */
|
|
syncIntervalMs?: number;
|
|
}
|
|
|
|
export function buildModules(o: E2EModuleOptions): ServerModule[] {
|
|
return [
|
|
authSettingsModule,
|
|
// TMDB 不注入:走设置 metadata.tmdbApiKeySecretRef / tmdbBaseUrl(W2 收口 b)
|
|
createSourcesIdentityModule({ schedulerIntervalMs: 3_600_000 }),
|
|
createAcquisitionOrganizeModule({
|
|
downloader: async (inst) =>
|
|
createQbClient({
|
|
instanceId: inst.id,
|
|
baseUrl: inst.base_url,
|
|
username: "admin",
|
|
password: "adminadmin",
|
|
lookup: { attempts: 5, intervalMs: 50 },
|
|
}),
|
|
torrentSource: async ({ release }) => ({ kind: "file", bytes: torrentFor(release.title).bytes }),
|
|
diskUsage: async (path) => ({
|
|
status: "ok",
|
|
path,
|
|
totalBytes: 1e12,
|
|
freeBytes: 6e11,
|
|
availableBytes: 6e11,
|
|
usedBytes: 4e11,
|
|
usedRatio: 0.4,
|
|
}),
|
|
probe: async () => ({ status: "unknown", reason: "ffprobe_unavailable" }),
|
|
options: {
|
|
backgroundLoops: true,
|
|
syncIntervalMs: o.syncIntervalMs ?? 300,
|
|
minVideoBytes: 100_000,
|
|
verifyHash: "sha256",
|
|
reconcileIntervalMs: 0,
|
|
},
|
|
}),
|
|
createAgentModule({
|
|
sessionDir: o.sessionDir,
|
|
...(o.fakeScripts ? { fakeScripts: o.fakeScripts } : {}),
|
|
goalPollSec: 1,
|
|
}),
|
|
];
|
|
}
|