fix(execution-truth): 修系統對 401 假綠根因 + acr run self-hosted + D1-in-update
Haiku 自主壓測(test_arcrun/5)暴露的真 bug,逐一修復:
1. 假綠根因:http_request host function 丟掉 HTTP status code(main.go:112 架構債)
→ 非 2xx(如 Notion 401)被判 success → 引擎自己對失敗報成功。
修:host fn 非 2xx 回 {error,status,body} envelope,既有判定鏈正確識別。
http_request/claude_api/kbdb_upsert_block/km_writer 已修(4 worker deploy);
auth_service_account 自有 OAuth 判定不套。
2. acr run self-hosted:原一律走 /webhooks/<name>(需先 push)→ 沒 push 回 404 純文字
→ res.json() 爆假錯誤。修:本機有 YAML 走玩法一 /cypher/execute 直接執行(三模式一致)
+ res.ok 擋非 2xx + findWorkflowYaml 容忍 .yaml 副檔名。
3. D1-in-update:D1 只在 init 建一次,update 漏建 → token 補權限後無冪等補建路徑。
修:update 也 ensureD1Database(已驗證 D1 建起 count:1)。
4. CF token 教學漏 D1:llms.txt/.env.example 加「Account/D1/Edit」必勾 + init/preflight
訊息指明 token 缺 D1 權限的修法。
CLI 1.3.4 publish。Haiku 壓測結論:onboarding 治好(裝+init 沒跳過、建 recipe 不建零件),
但仍會假綠(curl 繞過/D1 沒建謊報)→ 印證執行真相要系統能驗、不信 AI 自報。
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+38
-13
@@ -37,14 +37,14 @@ export async function cmdRun(workflowName: string, options: RunOptions): Promise
|
||||
const headers: Record<string, string> = { 'Content-Type': 'application/json' };
|
||||
if (config.api_key) headers['X-Arcrun-API-Key'] = config.api_key;
|
||||
|
||||
// ── 玩法一:Standard 模式,YAML 在本機,帶著打 /cypher/execute ──────────────
|
||||
if (config.mode === 'standard' || config.mode === 'local') {
|
||||
const yamlPath = findWorkflowYaml(workflowName);
|
||||
if (!yamlPath) {
|
||||
console.error(chalk.red(`找不到 ${workflowName}.yaml(在目前目錄或子目錄尋找)`));
|
||||
console.error(chalk.gray('玩法二(已 push 到 KV)請改用 Self-hosted 模式'));
|
||||
process.exit(1);
|
||||
}
|
||||
// ── 玩法一:本機有 YAML → 直接帶著打 /cypher/execute(不需先 push)──────────────
|
||||
// 2026-06-09 修:原本只有 standard/local 走這條,self-hosted 一律走玩法二(/webhooks/<name>,
|
||||
// 需先 push 到 KV)。導致 self-hosted 用戶(如壓測 Haiku)有本機 YAML 卻 acr run 直接打
|
||||
// /webhooks/<name> → 沒 push = 404 純文字 → res.json() 爆「Unexpected non-whitespace...」假錯誤。
|
||||
// 正解:只要本機找得到 YAML 就走玩法一直接執行(三模式一致);找不到才退玩法二(按名字打已 push 的)。
|
||||
const localYamlPath = findWorkflowYaml(workflowName);
|
||||
if (localYamlPath) {
|
||||
const yamlPath = localYamlPath;
|
||||
|
||||
let workflow;
|
||||
try {
|
||||
@@ -71,6 +71,14 @@ export async function cmdRun(workflowName: string, options: RunOptions): Promise
|
||||
}),
|
||||
});
|
||||
|
||||
// 非 2xx 先擋:直接 res.json() 對 404「Not Found」這種純文字會爆出誤導的
|
||||
// 「Unexpected non-whitespace character after JSON」。看 res.ok 給人話。
|
||||
if (!res.ok) {
|
||||
const body = await res.text();
|
||||
spinner.fail(chalk.red(`執行失敗(HTTP ${res.status}):${body.slice(0, 200)}`));
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const data = await res.json() as {
|
||||
success: boolean;
|
||||
data?: unknown;
|
||||
@@ -88,7 +96,7 @@ export async function cmdRun(workflowName: string, options: RunOptions): Promise
|
||||
return;
|
||||
}
|
||||
|
||||
// ── 玩法二:Self-hosted,workflow 已存在 KV,打 /webhooks/{name} ─────────────
|
||||
// ── 玩法二:本機沒這個 YAML → 按名字打已 push 到 KV 的 workflow ───────────────
|
||||
const spinner = ora(`執行 workflow "${workflowName}"`).start();
|
||||
try {
|
||||
const res = await fetch(`${executorUrl}/webhooks/${workflowName}`, {
|
||||
@@ -97,6 +105,20 @@ export async function cmdRun(workflowName: string, options: RunOptions): Promise
|
||||
body: JSON.stringify(inputContext),
|
||||
});
|
||||
|
||||
// 非 2xx 先擋(同玩法一):404 純文字別硬 res.json()。404 多半是「還沒 push」。
|
||||
if (!res.ok) {
|
||||
if (res.status === 404) {
|
||||
spinner.fail(chalk.red(`找不到已部署的 workflow "${workflowName}"`));
|
||||
console.error(chalk.gray(` 本機也沒有 ${workflowName}.yaml。請確認:`));
|
||||
console.error(chalk.gray(` ① 本機有 YAML → 在該檔所在目錄跑 acr run(會直接執行,不需先 push)`));
|
||||
console.error(chalk.gray(` ② 要跑已部署的 → 先 acr push <file>.yaml 再 acr run <name>`));
|
||||
} else {
|
||||
const body = await res.text();
|
||||
spinner.fail(chalk.red(`執行失敗(HTTP ${res.status}):${body.slice(0, 200)}`));
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const data = await res.json() as {
|
||||
success: boolean;
|
||||
data?: unknown;
|
||||
@@ -116,11 +138,14 @@ export async function cmdRun(workflowName: string, options: RunOptions): Promise
|
||||
// ── helpers ──────────────────────────────────────────────────────────────────
|
||||
|
||||
function findWorkflowYaml(name: string): string | null {
|
||||
// 容忍使用者直接給含副檔名的檔名(acr run foo.yaml)——剝掉再補,避免找成 foo.yaml.yaml。
|
||||
const base = name.replace(/\.(ya?ml)$/i, '');
|
||||
const candidates = [
|
||||
`${name}.yaml`,
|
||||
`${name}.yml`,
|
||||
`workflows/${name}.yaml`,
|
||||
`workflows/${name}.yml`,
|
||||
name, // 原樣(已含副檔名或本就是路徑)
|
||||
`${base}.yaml`,
|
||||
`${base}.yml`,
|
||||
`workflows/${base}.yaml`,
|
||||
`workflows/${base}.yml`,
|
||||
];
|
||||
for (const p of candidates) {
|
||||
if (existsSync(p)) return p;
|
||||
|
||||
Reference in New Issue
Block a user