Repository navigation
test(op): build test sessions through the real constructor, not literals - #410
Merged
Merged
Conversation
Phase 2b, PR 2b.1 of the native-Windows-permissions plan (#405). PARTIAL: 6 files converted; 13 files / 26 sites remain, named in the plan. RuntimeEnvironment.Root has to become an accessor so the root can be allocated lazily and owned by the session. Making the field private breaks every test that sets it in a struct literal, so those move onto the real constructor FIRST -- otherwise the field change and every test conversion land in one unreviewable commit and nothing is actually split. Each converted package gains a local testEnvironment(t, dir) helper that calls NewRuntimeEnvironment with a spec. Tests now travel the same construction path production does: the session mints the root from the spec's anchor rather than receiving filesystem access someone else opened. The conversion SHRINKS these tests. NewRuntimeEnvironment already wires RecoverySite and defaults ResourceCatalog, both of which several helpers were hand-assembling, so those lines are deleted rather than ported. A planned codegen PR turned out to be unnecessary. The receiver_type.gen_test.go template emits Application / Context / Status and never Root, so no generated file breaks -- verified by enumeration after an earlier estimate wrongly assumed every RuntimeEnvironment literal in the tests was affected. That is why this is three PRs rather than four. The plan records the remaining 13 files, the exact pattern, and three gotchas already hit once each: the constructor's defaulting means lines get deleted not ported; Application must be non-nil or the constructor asserts; and dropping the fsroot.Open* call orphans the fsroot import, which broke the build once here. No behavior change -- the Root field is still exported and still set by the constructor. make test reports zero failures. Assisted-by: Claude Signed-off-by: David Noble <[email protected]>
The conversion put "context" in a group of its own and dropped pkg/application into the stdlib block. gofmt accepts both -- it never reorders import groups -- so the local check passed and quality-gate failed on #410 with three goimports findings. Imports now follow the repository's stdlib / third-party / project grouping, placed by hand: golangci-lint fmt satisfies the linter but leaves pkg/application in a group by itself. Nothing local caught it because the check run before handing off was gofmt, which is not the gate CI runs. make lint-all is, and it reports the finding immediately. Run it before every commit that touches Go. Verified: make lint-all reports 0 issues on linux, darwin, and windows. test (windows-latest) held at the known 28 failures on the parent commit, confirming the conversion moved nothing on that leg. Assisted-by: Claude Signed-off-by: David Noble <[email protected]>
David-Noble-at-work
added a commit
that referenced
this pull request
Aug 14, 2026
Phase 2b of the native-Windows-permissions plan (#405) needed two design questions answered before its 82-site mechanical pass could start. Both are now ruled, with the reasoning and the rejected alternatives recorded so neither gets relitigated. Root: HasRoot() bool plus a Root() that panics when it is false, modeled on reflect.Value.IsValid -- whose doc states the rule once, whose panic is typed rather than a string, and whose discipline puts the burden on the producer to advertise. The case is real: cmd/lore/lore/builder.go builds a rootless session in production, and seven call sites nil-check the field today. Comma-ok was rejected on call-site distribution (75 of 82 sites structurally have a root); a bare nil was rejected because fsroot.Root is an interface, so nil relocates the panic into fsroot internals rather than preventing it. Scratch: no HasScratch -- root's absence is configured, scratch's is not configurable at all, so the predicate could only ever return true. Scratch() is an accessor to a per-session directory INSIDE the OS temp directory, never a root over the temp directory itself: OpenScratch's Close contract would delete the shared tree, confinement to a directory every process writes to isolates nothing, and only a directory of our own can be created 0700 and pick up phase 2's DACL protection -- which matters, because scratch holds the most sensitive transient data. os.TempDir() accessibility is preflighted at environment build like the root's anchor, and that decides the signature: preflighting supplies the validated premise, so a later MkdirTemp failure is a failure AFTER verification, which is an assert. Scratch() fsroot.Dir returns the directory alone, symmetric with Root(). fsroot.Dir gains CreateTemp and MkdirTemp, landing in 2b.2 alongside the accessors. A shared per-session directory needs unique names within it and gather dispatches bodies concurrently by design; os.CreateTemp gives that free today and Dir.Create does not. Both trees carry the methods, and the rule for choosing goes in both doc comments: use Scratch() unless the bytes must end up in the root's tree atomically, because a rename out of scratch can cross a device boundary. Phase 2 is marked complete. Its CI exit gate was met and never recorded: pkg/fsroot reports ok on test (windows-latest), so all six TestApplyMode DACL tests pass on a real runner and none appear in that leg's 28 known failures. Call sites are cleared to migrate. Also: PR 2b.1 split into 2b.1a (merged, #410) and 2b.1b (next), with a branch plan for the remaining 13 files and 26 sites naming both traps -- starcode's Root: lines are only half environment fields, and file/provider_test.go sets a BackupSuffix the constructor never defaults. The current-state table now separates Windows enforcement through fsroot, which works, from everywhere else, which does not. Recorded from the 2b.1a round-trip: make lint-all is the gate to run before handing off Go changes, not gofmt, which never reorders import groups. This repository runs no pre-commit hooks by decision. Assisted-by: Claude Signed-off-by: David Noble <[email protected]> Co-authored-by: David Noble <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2b, PR 2b.1 of
windows-native-permissions.md(#405). Partial by design: 6 files
converted; the remaining 13 files / 26 sites are listed in the plan.
RuntimeEnvironment.Rootmust become an accessor so the root can be allocated lazily and owned bythe session. Making the field private breaks every test that sets it in a struct literal — so those
move onto the real constructor first, or the field change and every test conversion land in one
unreviewable commit and nothing is actually split.
What changed
Each converted package gains a local
testEnvironment(t, dir)helper callingNewRuntimeEnvironmentwith a spec. Tests now travel the same construction path production does:the session mints the root from the spec's anchor instead of receiving access someone else opened.
The conversion shrinks these tests —
NewRuntimeEnvironmentalready wiresRecoverySiteanddefaults
ResourceCatalog, which several helpers were hand-assembling.A planned PR proved unnecessary
The
receiver_type.gen_test.gotemplate emitsApplication/Context/Statusand neverRoot, so no generated file breaks and the codegen PR is not needed. Verified by enumeration,after an earlier estimate wrongly assumed every
RuntimeEnvironmentliteral in the tests wasaffected.
Handoff
The plan records the remaining 13 files and 26 sites, the exact pattern, and three gotchas each hit
once: the constructor's defaulting means lines are deleted not ported;
Applicationmust benon-nil or the constructor asserts; and dropping the
fsroot.Open*call orphans thefsrootimport (which broke the build once here).
pkg/op/provider/file/provider_test.goadditionally setsBackupSuffix,which the constructor does not default.
No behavior change — the
Rootfield is still exported and still set by the constructor.make testreports zero failures.test (windows-latest)expected to hold at the known 28.Assisted-by: Claude