WeKnora/cli/cmd
SIRIUS 49e262147c
fix(cli): preserve directory structure in doc upload --recursive (#3753)
* fix(cli): preserve directory structure in doc upload --recursive

`doc upload --recursive` passed an empty customFileName to
CreateKnowledgeFromFile, so every file landed in the knowledge base root
and the directory tree it was asked to walk was lost. The web UI's folder
upload does not have this problem -- it passes the browser-supplied
relative path, which the server splits into folder_path + file_name via
types.SplitKnowledgeRelativePath.

Pass the path relative to the walked directory instead. Files directly
under that directory still send "" so the request stays byte-identical to
the previous behaviour for the common flat-directory case; only nested
files gain a folder prefix.

- knowledgeRelativePath() converts to forward slashes (the server splits on
  "/", so Windows backslashes would not separate) and returns "" for paths
  outside the walked root rather than leaking a "../" chain into the folder
  tree.
- The test double previously discarded customFileName with `_,` -- which is
  why this could regress with the suite green. It now records the value and
  two tests cover the nested and flat cases.

* fix(cli): reject only the parent component in knowledgeRelativePath

Review feedback on the recursive-upload folder path:

- `strings.HasPrefix(rel, "..")` also rejected children whose name merely
  starts with dots, e.g. `..drafts/report.pdf`. Replaced with a
  component-wise check (`rel == ".."` or `".."+separator` prefix).
- Root-level files must send ""; the guard now returns "" for
  `filepath.Dir(rel) == "."` explicitly rather than relying on the
  accidental prefix match to encode that rule.

Covered by a `..drafts/report.pdf` case in
TestUploadRecursive_PreservesFolderStructure.

* test(cli): expect an empty name for root files in knowledgeRelativePath

knowledgeRelativePath returns "" for files directly under the walked
root, so the test must expect that. Also wrap an over-long line.

---------

Co-authored-by: wizardchen <wizardchen@tencent.com>
2026-10-08 13:13:57 +08:00
..
agent fix(agent): PUT no longer erases the avatar, and driver errors stay server-side (#3230) 2026-09-14 20:50:15 +08:00
api fix(cli): render paginated API results in text mode (#3984) 2026-10-08 01:28:05 +08:00
auth fix(cli): preserve integer precision in jq output (#3991) 2026-10-08 01:28:25 +08:00
chat fix(cli): align stream/list interfaces with client ResourceURLOptions 2026-08-10 19:33:39 +08:00
chunk feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
config feat(cli): agent-first WeKnora CLI 2026-07-06 22:53:01 +08:00
doc fix(cli): preserve directory structure in doc upload --recursive (#3753) 2026-10-08 13:13:57 +08:00
doctor feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
kb feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
link feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
mcp feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
message fix(cli): align stream/list interfaces with client ResourceURLOptions 2026-08-10 19:33:39 +08:00
model feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
profile feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
search fix(auth): record last-active-tenant preference on SwitchTenant (#2922) 2026-09-01 15:43:40 +08:00
session fix(cli): apply list limits after filtering and sorting (#3990) 2026-10-08 01:28:19 +08:00
skills feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
agenthelp_coverage_test.go feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
completion_test.go feat(cli): api --input + completion smoke 2026-05-14 10:57:17 +08:00
coverage_helpers_test.go feat(cli): v0.9 contract harmonization 2026-06-08 20:18:43 +08:00
dryrun_coverage_test.go feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
exitcodes.go feat(cli): agent-first WeKnora CLI 2026-07-06 22:53:01 +08:00
exitcodes_test.go feat(cli): agent-first WeKnora CLI 2026-07-06 22:53:01 +08:00
required_positional_coverage_test.go feat(cli): agent-first WeKnora CLI 2026-07-06 22:53:01 +08:00
root.go feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
root_test.go feat(cli): v0.9 contract harmonization 2026-06-08 20:18:43 +08:00
root_unknown_subcommand_test.go feat(cli): agent-first WeKnora CLI 2026-07-06 22:53:01 +08:00
schema.go feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00
schema_test.go feat(cli)!: v0.10 reliability, agent-UX, and command-surface hardening 2026-07-06 22:53:01 +08:00