Files
qwen-code/integration-tests
易良andQwen-Coder 35aa4b76ae fix(core): require explicit trust for settings-file project hooks (#16196)
* fix(core): require explicit trust for settings-file project hooks

A repository .qwen/settings.json SessionStart hook ran at startup with
no trust prompt while the folder-trust feature was off by default:
getProjectHooks() consulted isTrustedFolder(), which returns trusted
when the feature is disabled. Gate it on isExplicitlyTrustedFolder()
instead, matching the frontmatter-hook and LSP gates from #16182.
Update the hooks docs, and grant explicit trust in hook test fixtures.

Refs #14746

Co-authored-by: Qwen-Coder <[email protected]>

* style(core): use Array<T> for the tuple-array cast

Co-authored-by: Qwen-Coder <[email protected]>

* test(integration): grant explicit trust in ACP parity fixtures

The ACP parity rig spawns the CLI with its own QWEN_HOME, so the trust
granted by TestRig.setup() never reaches those sessions. With project
hooks now requiring explicit folder trust, the UserPromptSubmit hook
scenarios silently lost their hooks. Seed the scenario home with folder
trust enabled and the rig directory trusted, matching the tool-hook
suites.

Co-authored-by: Qwen-Coder <[email protected]>

* fix(core): align project-hook trust with the interactive boundary

Follow the Claude Code model: interactive sessions keep the explicit
folder-trust gate, while non-interactive invocations (-p, piped stdin,
ACP/SDK embeddings) treat trust as implicit — the caller chose the
directory and there is no prompt surface. This keeps platform embedders
working without trust-file migration. Surface a startup warning when
interactive project hooks are withheld so the gate is not silent, and
document the headless contract. Revert the integration-fixture trust
grants that the headless exemption makes unnecessary.

Refs #14746

Co-authored-by: Qwen-Coder <[email protected]>

* test(integration): drop ACP parity trust seeding made moot by headless exemption

The parity rig spawns non-interactive ACP sessions, which now treat
trust as implicit, so the seeded trustedFolders.json only perturbed the
request-snapshot comparison (an extra tmp/ tree under .qwen-home).
Restore the fixture to its main-branch shape; all 23 parity cases pass.

Co-authored-by: Qwen-Coder <[email protected]>

* fix(cli): tolerate partial settings shapes in the project-hook warning

The startup warning read settings.workspace.settings.hooks without
optional chaining; AppContainer tests render with a partial
LoadedSettings mock, and a missing workspace scope crashed the effect
before config initialization completed. Guard the lookup; all 272
AppContainer tests pass.

Co-authored-by: Qwen-Coder <[email protected]>

* docs(hooks): resolve trust-gate wording contradictions (R1-5)

Troubleshooting step 3 still stated the legacy trusted-folder rule and
the restart list omitted security.folderTrust and persisted trust
decisions. Align both with the interactive explicit-trust gate and the
headless implicit-trust contract, and mention the withheld-hooks
startup warning and browser state.

Co-authored-by: Qwen-Coder <[email protected]>

* test(integration): drop dead ACP trust seeding in the tool-hook suites

The per-session trustedFolders.json written beside the QWEN_HOME override
is never read: getTrustedFoldersPath() prefers the inherited
QWEN_CODE_TRUSTED_FOLDERS_PATH that TestRig.setup() stubs. Both blocks sit
in front of an --acp spawn, and ACP sessions are non-interactive, so the
headless exemption already loads project hooks without any trust grant.
Remove the writes and the now-unused realpathSync import, restoring both
suites to their base shape.

Refs #14746

* test(cli): pin the folderTrust derivation behind the project-hook gate

The interactive gate is covered by the Config table, but nothing pinned
settings.security.folderTrust.enabled -> Config.folderTrust. Assert that
loadCliConfig derives it and defaults it to false, so a derivation
flipping to true cannot silently arm repo-supplied hooks. Verified the
case goes red when the default is mutated to true.

Refs #14746

* docs(hooks): align trust-boundary descriptions with implementation

Remove the unimplemented claim that withheld project hooks appear in the hook browser. Clarify that loop.md retains the legacy folder-trust predicate while executable project hooks use explicit interactive trust.

Co-authored-by: Qwen-Coder <[email protected]>

* fix(cli): keep folder trust out of workspace reach

The project-hook gate reads security.folderTrust.enabled from merged
settings, so a repository could enable the very flag that authorizes its
own hooks and then reach any pre-existing TRUST_FOLDER or TRUST_PARENT
rule for the directory. Restrict the key to the operator scopes, beside
allowPrivateNetworkHooks, and pin both directions: a workspace can
neither enable the gate nor disarm a user's setting.

Also close the smaller review notes. The startup warning no longer
blames trust when disableAllHooks removed the hook system entirely, and
it now has coverage for the warned and both silent branches. Every hook
fixture ran pre-trusted, so add an interactive integration case that
declines trust and asserts the hooks never fire, the warning names the
remedy, and the tool result still reaches the model unmarked. Drop the
duplicated node:fs import and correct the docs claim that IDE trust
decisions apply live to settings-file hooks.

Refs #14746

Co-authored-by: Qwen-Coder <[email protected]>

* test(cli): align the daemon trust-grant case with the workspace restriction

security.folderTrust is now stripped from workspace scope, so a grant on
a workspace that only self-enables trust reports the disabled state
instead of refusing an ineffective grant. Keep the alias DO_NOT_TRUST
fixture: if the restriction regresses, the grant throws again and this
case goes red (mutation-verified).

Fixes the Test (ubuntu-latest) failure on a89935fa.

* test(cli): follow operator trust in the ancestor-trust case

R1-22 asserted that a workspace folderTrust value reaches the merged
settings, which is the behavior the workspace restriction removes. Drive
the case from the operator's flag instead: the merged value must survive
the repo's opposing declaration, and the ancestor provider must follow
the operator — denying every ancestor on the target's DO_NOT_TRUST rule
when the feature is on, falling back to directory safety when it is off.
Mutation-verified: dropping the restriction turns both cases red.

Fixes the Test (ubuntu-latest) failure on 6851f531.

Co-authored-by: Qwen-Coder <[email protected]>

---------

Co-authored-by: Qwen-Coder <[email protected]>
2026-11-03 23:54:00 +08:00
..