Skip to content

fix(import): validate AI learning draft metadata - #1305

Merged
SaulMoro merged 1 commit into
Tencent:mainfrom
ydflow:fix/import-mr-draft-metadata
Oct 23, 2026
Merged

SaulMoro merged 1 commit into
Tencent:mainfrom
ydflow:fix/import-mr-draft-metadata

Conversation

@ydflow

@ydflow ydflow commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Summary

An MR learning can be valid YAML but still have the wrong metadata types: tags: agent crashes at tags.join, and title: 42 crashes at toLowerCase when the draft is queued. The AI call has already completed, but the learning is not saved.

Check the types before using these fields: use the MR title when the generated title is not a string, and display only string entries from a tags array. Keep the draft content as received by the importer. Update the English and Chinese knowledge guides.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Test Plan

  • npm run build
  • npx tsc --noEmit
  • npm run lint
  • npx vitest run src/__tests__/import-mr.test.ts src/__tests__/import-mr-threads.test.ts src/__tests__/import-mr-learnings-checkout.test.ts src/__tests__/ci-extract-mr.test.ts src/__tests__/contribute.test.ts --maxWorkers=3 — 57 tests passed.
  • npx vitest run --config vitest.windows.config.ts --maxWorkers=3 — 665 tests passed in 23 files.
  • npx vitest run --config vitest.e2e.config.ts src/__tests__/e2e/import-mr-draft-metadata.test.ts --maxWorkers=1 --retry=0 — the built CLI imported two MRs, one with scalar tags and one with normal tags; exit 0, 2 succeeded, 0 failed, and both saved drafts matched the fixture contents.
  • git diff --check

Before the fix, six of the nine added metadata regression cases failed, including the tags.join and queued-title toLowerCase errors. The tests cover output files, queued filenames, mixed tags and valid metadata.

Related Issues

Follow-up to #241: that change catches YAML parsing errors; these inputs parse successfully and fail when their field types are trusted.

Notes for Reviewers

Local validation ran on Windows with Node 24. The full POSIX unit suite and other provider/agent combinations are left to CI. The real-CLI E2E uses a local HTTP GitLab fixture and a deterministic AI subprocess; no live model or remote GitLab instance was used.

@github-actions

Copy link
Copy Markdown

No findings in the specified diff.

The title fallback and tags filtering address the reported crashes without rewriting draft content. Regression tests cover malformed metadata and queued filenames; both knowledge guides are updated.

The PR description documents sufficient testing, including a representative built-CLI E2E run that saved both drafts unchanged. Additional provider/agent coverage is explicitly deferred to CI.

Review was read-only; I did not run, build, or install PR code.

@SaulMoro SaulMoro left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This was generated by AI during triage.

@ydflow Thanks, this looks good. Approving.

We checked it with the built CLI on this head and on its base 97f1e7b4. A local GitLab stand-in served two MRs, and a stand-in claude returned the drafts:

draft base this PR
tags: agent (--output) exit 1, tags.join is not a function, one draft written exit 0, 2 succeeded, both drafts byte-equal to the input
title: 42 (queue) exit 1, toLowerCase is not a function, one draft queued exit 0, both queued, the second under the MR title

tsc, lint, the 57 unit tests and the new e2e pass on this head. On the base, 6 of the 9 new unit cases fail, and so does the new e2e. That matches the body.

Optional, not blocking:

  • [P3 nit] teamai ci extract-mr goes through the same function, but no test drives it with a non-string title.
  • [P3 nit] The knowledge.md paragraph describes a bugfix's internals more than behavior a user sets up, so it could be dropped under the "change docs rarely" rule. Fine to keep.

@SaulMoro
SaulMoro merged commit 61e51e9 into Tencent:main Oct 23, 2026
18 checks passed
Walternater pushed a commit to Walternater/teamai-cli that referenced this pull request Nov 2, 2026
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.

3 participants