Repository navigation
Add ExtensionActivation.root so extensions can resolve project-relative paths - #130
Merged
Merged
Conversation
…cwd()
urlcode-middleware needs to resolve project-relative middleware source
files (the same way core's own functionFile()/router.ts resolves native
function/middleware `source` entries) the same way core does, but
ExtensionActivation ({origin, target, projectSha256, mounts}) had no
project directory to resolve against. process.cwd() is not a substitute:
--project/--host-file are independent, arbitrary paths, a server can be
started from a different working directory than the project, and the JS
API can load a project programmatically with no relationship to cwd() at
all (confirmed by reading src/cli.ts/src/config.ts: loadDocument() takes
an explicit `project` path and resolves it via realpath(), independent of
cwd()).
- src/extensions.ts: adds `root: string` to ExtensionActivation, documented
as the project's resolved absolute directory, the same value functionFile()
resolves native sources against, and explicitly not process.cwd().
- src/runtime.ts: passes loaded.root (already computed there, already used
for compilePolicies and functionFile()) through to prepareExtensions'
context, so it reaches every RuntimeExtension's activate().
- test/extensions.test.ts: asserts activate() receives the resolved project
root, and adds a dedicated regression test that changes process.cwd() to
an unrelated directory before activation and confirms the observed root
is still the project's own resolved directory, not cwd().
- docs/SPIKE-CORE-LAYERING.md: records this as a second gap the middleware
extraction surfaced (alongside the wrap-semantics gap #129 already
closed), now resolved the same way.
Verification: npm run typecheck, npm run lint, npm run check, full
npm run verify (487 tests, 485 pass / 2 pre-existing skips, 0 fail).
Claude-Session: https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr
Co-Authored-By: Claude Sonnet 5 <[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.
Why
urlcode-middleware(a new, separate repo — seejimhoyd-com/urlcode-middleware)
needs to resolve project-relative middleware source files declared in its
policies.extensions.middlewareconfig (e.g.middleware/headers.mjs), thesame way core's own
functionFile()/router.tsresolves nativefunction/middlewaresourceentries against the project root. ButExtensionActivation({origin, target, projectSha256, mounts}) carries noproject directory to resolve against.
process.cwd()is not a reliable substitute — verified by readingsrc/cli.ts/src/config.ts:--project <directory>and--host-file <path>are independent, explicitpaths a caller passes; nothing ties them to the process's working directory.
urlcode serve --project DIRcan be started from any directory.createRuntime(project, options)(the JS API) accepts aprojectpathwith no relationship to
cwd()at all.loadDocument()already resolves the real project root viarealpath(project), independent ofcwd()— that'sloaded.root, alreadycomputed in
runtime.tsand already used forcompilePoliciesandfunctionFile()— but never passed toprepareExtensions()'s activationcontext.
This is the same category of small, additive contract gap PR #129 closed for
wrap semantics; this closes the equivalent gap for path resolution.
What changed
src/extensions.ts: addsroot: stringtoExtensionActivation,documented as the project's resolved absolute directory — the same value
functionFile()resolves native sources against — and explicitly notprocess.cwd().src/runtime.ts: passesloaded.rootthrough toprepareExtensions'scontext so every
RuntimeExtension.activate()receives it.test/extensions.test.ts: assertsactivate()receives the resolvedproject root, and adds a dedicated regression test that
chdirs to anunrelated directory before activation and confirms the observed root is
still the project's own resolved directory, not
cwd().docs/SPIKE-CORE-LAYERING.md: records this as a second gap the middlewareextraction surfaced (alongside the wrap-semantics gap Add ExtensionInstance.middleware: wrap semantics alongside authorize's gate #129 already closed),
now resolved the same way.
No schema change, no behavior change for existing extensions that don't read
context.root.Verification (real, not assumed)
npm run typecheck— cleannpm run lint— cleannpm run check— clean (llms-full.txt does not include SPIKE docs, so noregeneration needed)
npm run verify(lint + typecheck + check + build + full test suite) —487 tests, 485 pass, 2 pre-existing skips, 0 fail
Downstream dependency
jimhoyd-com/urlcode-middleware's
own implementation PR depends on this merging (and on this version of
@jimhoyd/urlcodebeing published) to resolvemiddleware/source filesagainst the real project root instead of guessing at
cwd().🤖 Generated with Claude Code
https://claude.ai/code/session_018neC2tYKPxMPbzZf1wNctr
Generated by Claude Code