Phase 2 Testing: Thread 生命周期 #2

Closed
opened 2026-05-06 04:35:28 +00:00 by xiaoju · 1 comment
Owner

验证目标

能启动 workflow thread,写入 JSONL 状态文件,查询运行状态,通过 IPC 终止指定 thread。

前置条件

Phase 1 完成,有一个已注册的 test workflow bundle。

# 注册测试 workflow(模拟 2 个 role,每 role sleep 2s)
bunx uncaged-workflow add test-slow /path/to/test-slow.mjs

测试步骤

Thread 持久化

  • Step 1: .data.jsonl 写入格式

    bun test packages/workflow/src/__tests__/thread-data.test.ts
    

    预期:

    • 第 1 行:start record(name, hash, threadId, parameters, timestamp)
    • 第 2+ 行:role output(role, content, meta, timestamp)
  • Step 2: .info.jsonl 写入格式

    bun test packages/workflow/src/__tests__/thread-info.test.ts
    

    预期: 每行 { tag, content, timestamp },tag 为 8-char Crockford Base32

进程模型

  • Step 3: 同 bundle 同进程

    bun test packages/workflow/src/__tests__/worker-process.test.ts
    

    预期: 同一 bundle 的多个 thread 在同一进程内执行,进程内用 thread pool 管理

  • Step 4: 全部 thread 完成后进程退出

    bun test packages/workflow/src/__tests__/worker-lifecycle.test.ts
    

    预期: 所有 thread 完成 → 进程自动退出,exit code 0

CLI 命令

  • Step 5: uncaged-workflow run

    bunx uncaged-workflow run test-slow --prompt "hello"
    

    预期: 输出 thread ID (ULID),后台启动执行

  • Step 6: uncaged-workflow ps

    bunx uncaged-workflow run test-slow --prompt "hello" &
    sleep 0.5
    bunx uncaged-workflow ps
    

    预期: 显示运行中的 thread(threadId, workflow name, 运行时长)

  • Step 7: uncaged-workflow kill

    THREAD_ID=$(bunx uncaged-workflow run test-slow --prompt "hello")
    sleep 0.5
    bunx uncaged-workflow kill $THREAD_ID
    bunx uncaged-workflow ps
    

    预期: 通过 IPC 终止指定 thread(不是 kill 进程),ps 中不再显示该 thread,同进程其他 thread 不受影响

  • Step 8: uncaged-workflow threads

    bunx uncaged-workflow threads test-slow
    

    预期: 列出该 workflow 所有历史 thread(threadId, 状态, 时间)

  • Step 9: uncaged-workflow thread <id>

    bunx uncaged-workflow thread $THREAD_ID
    

    预期: 显示 thread 的完整 .data.jsonl 内容(start + 各 role 输出)

  • Step 10: uncaged-workflow thread rm <id>

    bunx uncaged-workflow thread rm $THREAD_ID
    bunx uncaged-workflow threads test-slow
    

    预期: 删除 .data.jsonl + .info.jsonl,threads 列表中不再显示

验证完成标准

所有 checkbox 打勾
bun test 全部通过
IPC kill 不影响同进程其他 thread
JSONL 格式与 RFC-001 一致

Ref: #1

## 验证目标 能启动 workflow thread,写入 JSONL 状态文件,查询运行状态,通过 IPC 终止指定 thread。 ## 前置条件 Phase 1 完成,有一个已注册的 test workflow bundle。 ```bash # 注册测试 workflow(模拟 2 个 role,每 role sleep 2s) bunx uncaged-workflow add test-slow /path/to/test-slow.mjs ``` ## 测试步骤 ### Thread 持久化 - [ ] **Step 1: .data.jsonl 写入格式** ```bash bun test packages/workflow/src/__tests__/thread-data.test.ts ``` **预期:** - 第 1 行:start record(name, hash, threadId, parameters, timestamp) - 第 2+ 行:role output(role, content, meta, timestamp) - [ ] **Step 2: .info.jsonl 写入格式** ```bash bun test packages/workflow/src/__tests__/thread-info.test.ts ``` **预期:** 每行 `{ tag, content, timestamp }`,tag 为 8-char Crockford Base32 ### 进程模型 - [ ] **Step 3: 同 bundle 同进程** ```bash bun test packages/workflow/src/__tests__/worker-process.test.ts ``` **预期:** 同一 bundle 的多个 thread 在同一进程内执行,进程内用 thread pool 管理 - [ ] **Step 4: 全部 thread 完成后进程退出** ```bash bun test packages/workflow/src/__tests__/worker-lifecycle.test.ts ``` **预期:** 所有 thread 完成 → 进程自动退出,exit code 0 ### CLI 命令 - [ ] **Step 5: `uncaged-workflow run`** ```bash bunx uncaged-workflow run test-slow --prompt "hello" ``` **预期:** 输出 thread ID (ULID),后台启动执行 - [ ] **Step 6: `uncaged-workflow ps`** ```bash bunx uncaged-workflow run test-slow --prompt "hello" & sleep 0.5 bunx uncaged-workflow ps ``` **预期:** 显示运行中的 thread(threadId, workflow name, 运行时长) - [ ] **Step 7: `uncaged-workflow kill`** ```bash THREAD_ID=$(bunx uncaged-workflow run test-slow --prompt "hello") sleep 0.5 bunx uncaged-workflow kill $THREAD_ID bunx uncaged-workflow ps ``` **预期:** 通过 IPC 终止指定 thread(不是 kill 进程),ps 中不再显示该 thread,同进程其他 thread 不受影响 - [ ] **Step 8: `uncaged-workflow threads`** ```bash bunx uncaged-workflow threads test-slow ``` **预期:** 列出该 workflow 所有历史 thread(threadId, 状态, 时间) - [ ] **Step 9: `uncaged-workflow thread <id>`** ```bash bunx uncaged-workflow thread $THREAD_ID ``` **预期:** 显示 thread 的完整 .data.jsonl 内容(start + 各 role 输出) - [ ] **Step 10: `uncaged-workflow thread rm <id>`** ```bash bunx uncaged-workflow thread rm $THREAD_ID bunx uncaged-workflow threads test-slow ``` **预期:** 删除 .data.jsonl + .info.jsonl,threads 列表中不再显示 ## 验证完成标准 ✅ 所有 checkbox 打勾 ✅ `bun test` 全部通过 ✅ IPC kill 不影响同进程其他 thread ✅ JSONL 格式与 RFC-001 一致 Ref: #1
Author
Owner

Phase 2 验证结果

所有 Step 全部通过:

  • Step 1: .data.jsonl 写入格式 — start record + role record keys 验证通过
  • Step 2: .info.jsonl 写入格式 — tag/content/timestamp JSONL 验证通过
  • Step 3: 同 bundle 同进程 — worker TCP IPC 模型验证通过
  • Step 4: 全部 thread 完成后进程退出 — idle 后自动退出验证通过
  • Step 5: uncaged-workflow run — 启动 thread,输出 thread ID
  • Step 6: uncaged-workflow ps — 列出运行中 thread(.running 文件机制)
  • Step 7: uncaged-workflow kill — IPC 终止单个 thread,同进程其他 thread 不受影响
  • Step 8: uncaged-workflow threads — 列出历史 thread
  • Step 9: uncaged-workflow thread <id> — 展示 .data.jsonl 内容
  • Step 10: uncaged-workflow thread rm — 删除 thread 文件

补充验证

  • bun test — 32 tests, 0 fail
  • bun run check (biome) — 54 files, no errors
  • Engine: moderator 循环 planner→coder→END 正确
  • AbortController kill 不影响同进程其他 thread

设计备注

  • Bundle 契约升级:default export 为 WorkflowDefinition(含 name/roles/moderator),不再是裸函数
  • Worker 使用 TCP IPC(一行 JSON + \n),同时支持 Node fork IPC
  • 运行中 thread 用 .running 文件标记,比解析 JSONL 更可靠

小橘 🍊(NEKO Team)

## Phase 2 验证结果 ✅ 所有 Step 全部通过: - ✅ Step 1: .data.jsonl 写入格式 — start record + role record keys 验证通过 - ✅ Step 2: .info.jsonl 写入格式 — tag/content/timestamp JSONL 验证通过 - ✅ Step 3: 同 bundle 同进程 — worker TCP IPC 模型验证通过 - ✅ Step 4: 全部 thread 完成后进程退出 — idle 后自动退出验证通过 - ✅ Step 5: `uncaged-workflow run` — 启动 thread,输出 thread ID - ✅ Step 6: `uncaged-workflow ps` — 列出运行中 thread(.running 文件机制) - ✅ Step 7: `uncaged-workflow kill` — IPC 终止单个 thread,同进程其他 thread 不受影响 - ✅ Step 8: `uncaged-workflow threads` — 列出历史 thread - ✅ Step 9: `uncaged-workflow thread <id>` — 展示 .data.jsonl 内容 - ✅ Step 10: `uncaged-workflow thread rm` — 删除 thread 文件 ### 补充验证 - ✅ `bun test` — 32 tests, 0 fail - ✅ `bun run check` (biome) — 54 files, no errors - ✅ Engine: moderator 循环 planner→coder→END 正确 - ✅ AbortController kill 不影响同进程其他 thread ### 设计备注 - Bundle 契约升级:default export 为 `WorkflowDefinition`(含 name/roles/moderator),不再是裸函数 - Worker 使用 TCP IPC(一行 JSON + \n),同时支持 Node fork IPC - 运行中 thread 用 `.running` 文件标记,比解析 JSONL 更可靠 小橘 🍊(NEKO Team)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#2