Skip to content

fix(import-markdown): CI測試登記 + .md目錄skip保護 (#588)#589

Open
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882:fix/import-markdown-followup
Open

fix(import-markdown): CI測試登記 + .md目錄skip保護 (#588)#589
jlin53882 wants to merge 2 commits intoCortexReach:masterfrom
jlin53882:fix/import-markdown-followup

Conversation

@jlin53882
Copy link
Copy Markdown
Contributor

Summary

Follow-up to PR #482, addressing two issues identified by maintainer @app3apps:

Issue #588: #588


Fix 1:CI manifest 沒有 import-markdown 測試

test/import-markdown/import-markdown.test.mjs 沒有被加進 CI manifest,所以 npm run test 不會跑這個測試。

修復scripts/ci-test-manifest.mjs — 在 cli-smoke 群組加入 entry:

{ group: "cli-smoke", runner: "node", file: "test/import-markdown/import-markdown.test.mjs", args: ["--test"] }

Fix 2:.md 目錄讓 import abort

memory/ 下有一個實際是目錄但命名像 .md 檔案(例如 2026-04-11.md 資料夾),readdir 會把它列出來,f.endsWith('.md') 會通過,後續 readFileEISDIR 錯誤導致整個 import abort。

修復cli.ts — 讀每個 .md 檔前先 stat 確認 isFile(),非檔案就 skip 並 log warn:

const stats = await fsPromises.stat(filePath);
if (!stats.isFile()) {
  console.warn(`  [skip] not a file: ${filePath}`);
  skipped++;
  continue;
}
content = await fsPromises.readFile(filePath, "utf-8");

新增測試

test/import-markdown/import-markdown.test.mjs — 新增「skip non-file .md entries」測試:

  • 建立 memory/2026-04-12.md 為目錄(不是檔案)
  • 同時建立正常的 memory/2026-04-11.md
  • 確認 import 不 abort,正常檔案仍被匯入

測試結果:pass 13 / fail 0


Ref: app3apps 在 PR #482 issuecomment-4229349438 的 comment

Closes: Issue #588

- cli.ts: 讀檔前先stat確認isFile(),非檔案skip並log warn
- ci-test-manifest.mjs: 加入import-markdown.test.mjs到cli-smoke群組
- import-markdown.test.mjs: 新增測試『skip .md directory』

Ref: PR CortexReach#482 issuecomment-4229349438 (app3apps)
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4a9c2e7091

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

{ group: "core-regression", runner: "node", file: "test/strip-envelope-metadata.test.mjs", args: ["--test"] },
{ group: "cli-smoke", runner: "node", file: "test/cli-smoke.mjs" },
{ group: "cli-smoke", runner: "node", file: "test/functional-e2e.mjs" },
{ group: "cli-smoke", runner: "node", file: "test/import-markdown/import-markdown.test.mjs", args: ["--test"] },
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep CI baseline verifier in sync with manifest changes

Adding test/import-markdown/import-markdown.test.mjs to CI_TEST_MANIFEST breaks the repo’s test entrypoint because scripts/verify-ci-test-manifest.mjs enforces an exact baseline list/order and does not include this new file. In this state, node scripts/verify-ci-test-manifest.mjs (and therefore npm test) fails immediately with unexpected manifest entry, so CI cannot run the intended test suite.

Useful? React with 👍 / 👎.

- cli.ts: 讀檔前先stat確認isFile(),非檔案skip並log warn
- ci-test-manifest.mjs: 加入import-markdown.test.mjs到cli-smoke群組
- import-markdown.test.mjs: 新增測試『skip .md directory』

Ref: PR CortexReach#482 issuecomment-4229349438 (app3apps)
@jlin53882
Copy link
Copy Markdown
Contributor Author

PR #589 CI cli-smoke 失敗說明

cli-smoke 測試失敗不是本 PR 造成的,是 pre-existing 問題(源於 PR #582)。

失敗現象

  • cli-smoke.mjs:316: assert.equal(recallResult.details.count, 1) → 實際值為 0undefined

根因分析

PR #582(「skip 75ms retry when store is empty」)在 retrieveWithRetry() 中新增了以下邏輯:

// src/tools.ts:178-182
let results = await retriever.retrieve(params);
if (results.length === 0) {
  if (countStore) {
    const total = await countStore();
    if (total === 0) return results;  // ← 這裡直接返回,不等第二次 retry
  }
  await sleep(75);
  results = await retriever.retrieve(params);
}

cli-smoke.mjs 的 mock store.count() 回傳 0(因為測試的 store 是空的):

store: {
  async patchMetadata() {},
  // count() 故意不回傳任何值,或回傳 0
}

這導致即使 retriever 的第二次呼叫會回傳結果,邏輯也會在第一次就短路返回,第二次 retrieve 永遠不會執行。

驗證方式

# 在 upstream/master(無本 PR)上同樣失敗
git checkout upstream/master
npm run test:cli-smoke
# → FAIL: CLI smoke test failed(與本 PR 的 CI 失敗完全相同)

# 本 PR 只改了 4 個檔案,cli-smoke.mjs 不在其中
git diff upstream/master -- test/cli-smoke.mjs
# → (無輸出,cli-smoke.mjs 完全未修改)

修復建議

cli-smoke.mjs 的 mock store.count() 需回傳非零值,讓「skip retry when empty」邏輯不要觸發:

store: {
  async patchMetadata() {},
  async count() { return 1; },  // 新增:讓 PR #582 的優化邏輯不要觸發
}

本 PR 內容(均無問題)

檔案 變更
cli.ts +stat 檢查 + try/catch,解決 .md 目錄造成 EISDIR abort
scripts/ci-test-manifest.mjs +import-markdown 測試 entry
scripts/verify-ci-test-manifest.mjs +EXPECTED_BASELINE entry
test/import-markdown/import-markdown.test.mjs 新增 13 個測試,全數通過

本 PR 解決了 Issue #588 的兩個問題,CI 中 cli-smoke 失敗為既有問題,與本 PR 無關。建議 maintainer 另開 Issue 追蹤 cli-smoke mock 更新。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant