Repository navigation
fix: expand ~ and resolve relative workspace paths - #24
Conversation
The workspace path reached `docker run -v <path>:/workspace` exactly as typed. The onboard prompt returns raw text, so `~/silo-workspace` (one of the examples the CLI reference gives) was saved as-is and mkdir created a literal "./~/silo-workspace", while a bare name such as `ws` would make Docker mount a named volume instead of the host folder. `start --workspace` passed its value through the same way. --mount sources already went through expandHostPath() in start.ts. Move it to src/utils/paths.ts and use it for the workspace too: - onboard expands the answer before creating the directory and saving it. - start expands --workspace and the configured path, so configs saved before this fix work without re-running onboard. - doctor checks the expanded path, so a "~/…" config isn't reported as a missing directory, and its fix hint no longer suggests mkdir -p "~/…" (quoted, so a shell creates a literal "~"). Fixes SilosLabs#23
|
Thanks, this is great, but there are some minor issues here. I have also added some suggestions that we can implement along. Two things I'd like addressed before merge: 1. Existing configs with a bare name lose their data 2. workspacePath: expandHostPath(opts.workspace || config.sandbox.workspacePath),Smaller things, fine here or in a follow-up:
|
Review follow-up for SilosLabs#24. - Older configs could hold a bare name such as `ws`, which Docker mounted as the named volume `ws`. Switching that to `$CWD/ws` would hide the user's files. A new resolveWorkspaceMount() keeps mounting the volume when it exists, with a warning and steps to move to a host folder, and otherwise refuses a relative configured path instead of guessing a base folder. - An empty --workspace ("-w $WS" with WS unset) falls back to the config again, instead of resolving to the current directory. - start refuses a workspace folder that doesn't exist, as --mount already does (on Linux, Docker would create it owned by root). - expandHome()/expandHostPath() also expand Windows-style "~\". - doctor reports exactly what start would mount; status shows the ~-expanded path. - Tests: resolveWorkspaceMount unit tests (injected volume lookup), the -v source in buildRunFlags, and CLI tests for doctor recognising a volume and start refusing a bare name with no volume or a missing folder.
|
Thanks for the careful review. You're right on both blockers. 2972f64 addresses them, and the PR description is updated to match. 1. Bare-name configs:
2. Smaller things:
394 tests are passing and CI is green. |
Fixes #23
Problem
The workspace path went to
docker run -v <path>:/workspaceexactly as typed:~/silo-workspace, one of the examples indocs/cli-reference.md, literally, andmkdircreated a./~/silo-workspacedirectory.start --workspacepassed its value through unchanged.Docker treats a non-absolute
-vsource as a volume name. A barewstherefore mounted a named volume instead of the host folder, and~/…or./…failed.Change
src/utils/paths.ts:expandHome()expands~,~/…and~\….expandHostPath()also resolves relative paths. It moved here, unchanged in behaviour, fromstart.ts, where--mountuses it.isVolumeName()applies Docker's local volume-name rule.onboardexpands the workspace answer before creating the directory and saving the config.resolveWorkspaceMount()(src/utils/workspace.ts) is the single place that decides the/workspacesource:--workspacewins. An empty one falls back to the config, instead of resolving to the current directory.~is expanded, and the folder must exist, as--mountsources must.wsand that Docker volume exists,startkeeps mounting the volume, warns, and prints how to copy the files to a host folder. With no such volume, it refuses with a clear message rather than guessing a base folder. The same applies to any other relative path in the config.--workspaceon the command line resolves against the current directory, as a shell user expects.startuses it before touching any container, so a bad path fails cleanly, and logs(Docker volume)when it mounts one.doctorreports exactly whatstartwould mount.statusshows the~-expanded path.docs/cli-reference.mddescribes the workspace mount rules and the--workspacefallback.Tests
tests/utils/paths.test.ts:~,~/x,~\x, a bare name, relative segments, an absolute path,~other,expandHome, andisVolumeName.tests/utils/workspace.test.ts: every branch ofresolveWorkspaceMount, with an injected volume lookup, including the empty--workspaceand the existing-volume cases.tests/docker/templates.test.ts: the resolved source lands in--volume <source>:/workspace:rw, for a folder and for a named volume.tests/commands/onboard.test.ts:~/silo-wsandsilo-wsare saved as absolute paths. Both cases fail onmain.tests/cli.test.ts, using the fakedockerwith a newvolume inspectcase:doctoron a~/wsconfig;doctorrecognising a bare-name volume;startrefusing a bare name with no volume;startrefusing a missing folder.npm run typecheck,npm test(394 passing) andnpm run buildare green. The branch merges cleanly with #13.Not verified live: Docker wasn't running on this machine, so the Docker-side behaviour (a named volume for a bare name, an error for
~/…) comes from Docker's documented-vbehaviour.