-
Notifications
You must be signed in to change notification settings - Fork 11.8k
Add deterministic contribution IDs and stack lookup IDs for resolved artifacts #4261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
45800c2
Add deterministic contribution IDs and stack lookup IDs for resolved …
nicolehaugen c04e6d7
Remove trailing blank line
Copilot ec2191d
Fix markdownlint blank lines
Copilot e29d289
Align hook contribution IDs with installation
Copilot f7a7395
Align hook contribution ordering with installer semantics
Copilot 5343edd
Validate identifier components for all named contribution names
Copilot 1dbd291
Address contribution ID docs feedback
Copilot 1645341
Align contribution ID test coverage summary
Copilot b0015cf
docs: clarify preset kind hook note (Assisted-by: GitHub Copilot, aut…
Copilot 388a968
fix: use manifest ID for extension lookup IDs
Copilot 09089e2
refactor: omit unused extension manifest ID
Copilot 3bd2b1d
docs: clarify extension contribution source IDs
Copilot d1dac36
fix: validate extension command collisions on load
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| """Deterministic identifiers for Spec Kit contributions and resolved stack layers. | ||
|
|
||
| Every command, template, script, and hook contribution surfaced by a preset or | ||
| extension manifest carries a computed opaque ``id`` string, and every layer of a | ||
| resolved artifact stack carries a matching ``lookupId``. The identifier value is | ||
| derived only from author-declared manifest data — it never depends on file | ||
| contents, timestamps, archive hashes, installation directory paths, install-time | ||
| random values, or list positions. That is what makes identifiers portable | ||
| across machines, project locations, and reinstalls, and what lets consumers use | ||
| them as stable join keys. | ||
|
|
||
| Grammar for named contributions (commands, templates, scripts):: | ||
|
|
||
| id = "{layer}:{sourceId}:{kind}:{name}" | ||
|
|
||
| layer ∈ {"core", "preset", "extension"} | ||
| sourceId = "_" when layer == "core"; the preset id or extension id otherwise | ||
| kind ∈ {"command", "template", "script", "hook"} | ||
| name = the contribution's declared ``name`` | ||
|
|
||
| Hook identifiers use ``{eventName}:{command}`` as the name component:: | ||
|
|
||
| id = "{layer}:{sourceId}:hook:{eventName}:{command}" | ||
|
|
||
| Extension hook contributions use the same last-write-wins behavior as hook | ||
| installation, so at most one contribution exists for each | ||
| ``(eventName, command)`` pair. | ||
|
|
||
| The functions in this module are pure — inputs are strings or in-memory | ||
| mappings parsed from a manifest, outputs are strings. None of them read from | ||
| disk, look at ``os.environ``, call ``datetime``, or hash file contents. That | ||
| guarantee is what preserves portability, and it is enforced by inspection | ||
| rather than by runtime checks: any change here that adds an ambient input is a | ||
| change that breaks the identifier contract. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
|
|
||
| PROJECT_OVERRIDE_LAYER = "project" | ||
| """Resolver-only layer label for project-local override layers. | ||
|
|
||
| Project overrides are a resolver feature — they are not backed by any manifest | ||
| contribution. When a resolved artifact stack contains a project-override layer, | ||
| its ``lookupId`` uses this label so the round-trip invariant (every layer | ||
| carries a ``lookupId``) still holds. No manifest ``iter_contributions()`` will | ||
| ever emit a matching ``id``, so consumers see "not found" for the lookup, which | ||
| is the correct outcome for a layer with no originating manifest entry. | ||
| """ | ||
|
|
||
| class IdentifierComponentError(ValueError): | ||
| """Raised when a manifest component would break identifier grammar.""" | ||
|
|
||
|
|
||
| def validate_component(value: Any, field_label: str) -> str: | ||
| """Return ``value`` unchanged if it is a non-empty ``:``-free string. | ||
|
|
||
| Manifest components that appear in an identifier (``layer``, ``sourceId``, | ||
| ``kind``, ``name``, ``eventName``, ``command``) may not contain the ``:`` | ||
| delimiter — the grammar has no escape rule. This function is the guard used | ||
| by manifest validators to reject offending values at load time with a clear | ||
| message naming the field. | ||
| """ | ||
| if not isinstance(value, str): | ||
| raise IdentifierComponentError( | ||
| f"Invalid {field_label}: expected a string, got {type(value).__name__}" | ||
| ) | ||
| if not value: | ||
| raise IdentifierComponentError( | ||
| f"Invalid {field_label}: value must not be empty" | ||
| ) | ||
| if ":" in value: | ||
| raise IdentifierComponentError( | ||
| f"Invalid {field_label} '{value}': ':' is reserved as an identifier delimiter" | ||
| ) | ||
| return value | ||
|
|
||
|
|
||
| def derive_named_id(layer: str, source_id: str, kind: str, name: str) -> str: | ||
| """Build the identifier string for a named contribution kind. | ||
|
|
||
| Callers are expected to have already validated each component with | ||
| :func:`validate_component` at manifest-load time; this function does not | ||
| revalidate — it is a pure string join so the identifier can be computed | ||
| cheaply on every read. | ||
| """ | ||
| return f"{layer}:{source_id}:{kind}:{name}" | ||
|
|
||
|
|
||
| def derive_hook_id( | ||
| layer: str, | ||
| source_id: str, | ||
| event_name: str, | ||
| command: str, | ||
| ) -> str: | ||
| """Build the identifier string for a hook contribution.""" | ||
| return f"{layer}:{source_id}:hook:{event_name}:{command}" |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.