Skip to content

fix(faq): preserve disabled state when importing entries - #4581

Merged
lyingbug merged 2 commits into
Tencent:mainfrom
Jarvis636431:fix/faq-import-disabled-state
Oct 21, 2026
Merged

lyingbug merged 2 commits into
Tencent:mainfrom
Jarvis636431:fix/faq-import-disabled-state

Conversation

@Jarvis636431

@Jarvis636431 Jarvis636431 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Description

FAQ imports that explicitly set is_enabled=false currently create enabled entries. GORM applies the Chunk model's default:true to a zero-valued bool even when the insert uses Select("*"), and also mutates the caller's chunk before indexing.

Use an insert-only projection with a non-nil boolean pointer so both enabled and disabled states are explicit. Embed the original chunk so generated sequence IDs and timestamps continue to populate it. The existing model, database defaults, and FAQ default-enabled behavior are preserved; no migration or dependency changes are required.

Type of Change

  • 🐛 Bug fix
  • 🧪 Test

Related Issue

Fixes #4571

Testing

Passed:

GOMAXPROCS=2 go test -p 1 ./internal/application/repository -count=1 -timeout=3m
GOMAXPROCS=2 go test -p 1 ./internal/application/service -run 'FAQ|Faq' -count=1 -timeout=3m
GOMAXPROCS=2 GOFLAGS=-p=1 GOTOOLCHAIN=go1.26.2 golangci-lint run --concurrency=2 --new-from-rev=upstream/main --timeout=10m ./internal/application/repository ./internal/application/service
git diff --check upstream/main...HEAD

Lint used v2.12.2 and reported 0 issues. Repository tests used Go 1.27.1. The service package and repeated import regression also pass with CI's Go 1.26.2 toolchain:

GOMAXPROCS=2 LOG_FORMAT= GOTOOLCHAIN=go1.26.2 go test -p 1 ./internal/application/service -run '^TestFAQImportPreservesEnabledStateInStorageAndIndex

- SQLite tests read back mixed enabled/disabled batches, including 502 chunks crossing the SQL batch boundary, and verify caller state, sequence IDs, and timestamps.
- PostgreSQL SQL-mock coverage checks actual bound boolean arguments and generated `seq_id` writeback; this is not a live PostgreSQL integration test.
- The real FAQ import service and chunk persistence path are exercised in append and replace modes with enabled, disabled, and omitted states. Both persisted rows and captured retrieval-index inputs are checked; index assertions match by Chunk ID because deduplication does not preserve order. Each test closes its SQLite connection so repeated runs remain isolated. Model and retrieval services are test doubles.
- Running the final two-row SQLite regression with the unchanged upstream `chunk.go` overlaid fails because both the stored and caller states become `true`; the fixed implementation passes.

Full-repository checks and a browser/Excel end-to-end import were not run. An initial parallel lint attempt timed out loading dependencies under local memory pressure; the lower-concurrency scoped command above passed.

## Checklist

- [x] Diff whitespace check passes
- [x] Changed Go files are formatted
- [x] Repository package and FAQ-related service tests pass
- [x] Diff-scoped lint passes
- [x] Self-reviewed
- [x] Added regression coverage
- [x] Validation scope and limitations documented
- [x] No public API, schema, or dependency changes

Documentation and screenshots: not applicable; this fixes the existing import state contract without a UI change.
 -count=100 -timeout=3m
uv run --no-project --python 3.12 -- env GOMAXPROCS=2 LOG_FORMAT= GOTOOLCHAIN=go1.26.2 go test -p 1 ./internal/application/service -count=1 -timeout=4m
  • SQLite tests read back mixed enabled/disabled batches, including 502 chunks crossing the SQL batch boundary, and verify caller state, sequence IDs, and timestamps.
  • PostgreSQL SQL-mock coverage checks actual bound boolean arguments and generated seq_id writeback; this is not a live PostgreSQL integration test.
  • The real FAQ import service and chunk persistence path are exercised in append and replace modes with enabled, disabled, and omitted states. Both persisted rows and captured retrieval-index inputs are checked; model and retrieval services are test doubles.
  • Running the final two-row SQLite regression with the unchanged upstream chunk.go overlaid fails because both the stored and caller states become true; the fixed implementation passes.

Full-repository checks and a browser/Excel end-to-end import were not run. An initial parallel lint attempt timed out loading dependencies under local memory pressure; the lower-concurrency scoped command above passed.

Checklist

  • Diff whitespace check passes
  • Changed Go files are formatted
  • Repository package and FAQ-related service tests pass
  • Diff-scoped lint passes
  • Self-reviewed
  • Added regression coverage
  • Validation scope and limitations documented
  • No public API, schema, or dependency changes

Documentation and screenshots: not applicable; this fixes the existing import state contract without a UI change.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T10:01:15.795113Z a10076f New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lyingbug
lyingbug merged commit 9981c9f into Tencent:main Oct 21, 2026
4 checks passed
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.

[Bug]: FAQ Excel 导入时“是否停用=TRUE”未生效,新条目被默认启用

2 participants