Repository navigation
skills: serve the bundled snapshot when no skills folder is set #8199
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
Changes from all commits
a505271
9d8d254
e0eb4bb
c232ab1
cb4b064
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,10 +8,10 @@ import ( | |
| "time" | ||
| ) | ||
|
|
||
| // bundledSnapshot is a skills release compiled into the binary. It is the | ||
| // fallback for when the published release cannot be reached and nothing is | ||
| // cached. The repo holds only an empty manifest; a later change fills the | ||
| // snapshot when release binaries are built. | ||
| // bundledSnapshot is a skills release compiled into the binary. Resolve serves | ||
| // it today when no skills folder is set; once the live release and the cache | ||
| // exist it stays the last fallback. The repo holds only an empty manifest; a | ||
| // later change fills the snapshot when release binaries are built. | ||
| // | ||
| // The all: prefix embeds files whose names start with "." or "_" too. Without | ||
| // it the compiler drops them silently, and a skill file such as | ||
|
|
@@ -23,7 +23,8 @@ var bundledSnapshot embed.FS | |
| // BundledLabel says where a catalog from the bundled snapshot came from. | ||
| const BundledLabel = "bundled copy" | ||
|
|
||
| // bundledFS is the root of the compiled-in snapshot. | ||
| // bundledFS is the root of the compiled-in snapshot. Tests replace it through | ||
| // SetBundledFSForTest to serve a snapshot that has skills. | ||
| var bundledFS = subSnapshot() | ||
|
|
||
| func subSnapshot() fs.FS { | ||
|
|
@@ -34,15 +35,25 @@ func subSnapshot() fs.FS { | |
| return sub | ||
| } | ||
|
|
||
| // SetBundledFSForTest makes the bundled source serve fsys, a release laid out | ||
| // like the snapshot folder. It returns a function that restores the compiled-in | ||
| // snapshot. It is for tests only, and tests that call it must not run in | ||
| // parallel. | ||
| func SetBundledFSForTest(fsys fs.FS) (restore func()) { | ||
| prev := bundledFS | ||
| bundledFS = fsys | ||
| return func() { bundledFS = prev } | ||
| } | ||
|
|
||
| // NewBundledSource returns the source over the snapshot compiled into the | ||
| // binary. A snapshot with no skills reports ErrSourceUnreachable, so a | ||
| // development build behaves as if it had no bundled copy. | ||
| func NewBundledSource() Source { | ||
| return newBundledSource(bundledFS) | ||
| } | ||
|
|
||
| // newBundledSource serves a snapshot rooted at fsys. Tests pass a fixture | ||
| // release here, so they do not swap the package variable. | ||
| // newBundledSource serves a snapshot rooted at fsys. NewBundledSource passes | ||
| // the package variable here; tests replace that through SetBundledFSForTest. | ||
| func newBundledSource(fsys fs.FS) Source { | ||
| return &bundledSource{src: NewFSSource(fsys, BundledLabel)} | ||
| } | ||
|
|
@@ -52,8 +63,8 @@ type bundledSource struct { | |
| } | ||
|
|
||
| // Catalog reports the snapshot as a stale copy with no fetch time. The binary | ||
| // does not record when the snapshot was built, and the snapshot is only used | ||
| // when the release cannot be reached, so it is never current. | ||
| // does not record when the snapshot was built, so it is never reported as | ||
| // current. | ||
| func (s *bundledSource) Catalog(ctx context.Context) (*Catalog, error) { | ||
| catalog, err := s.src.Catalog(ctx) | ||
| if err != nil { | ||
|
|
@@ -73,3 +84,15 @@ func (s *bundledSource) ReadFile(ctx context.Context, skill, file string) ([]byt | |
| } | ||
| return s.src.ReadFile(ctx, skill, file) | ||
| } | ||
|
|
||
| // FileSize forwards to the snapshot, so list-files reports sizes for it too. | ||
| func (s *bundledSource) FileSize(ctx context.Context, skill, file string) (int64, error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nice to have] No test calls the new
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a FileSize case to TestBundledSourceFromFixture and TestBundledSourceFileSizeEmptySnapshot for the empty snapshot guard. |
||
| if _, err := s.Catalog(ctx); err != nil { | ||
| return 0, err | ||
| } | ||
| sizer, ok := s.src.(FileSizer) | ||
| if !ok { | ||
| return 0, fmt.Errorf("%w: %q in skill %q", ErrNoSize, file, skill) | ||
| } | ||
| return sizer.FileSize(ctx, skill, file) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nice to have]
provenanceLinenow selects the wording bycatalog.Label, not bycatalog.FetchedAt.IsZero(). TheCatalog.FetchedAtdoc says that a zero time means "unknown" for any source. If a later source returns a stale catalog with a zeroFetchedAtand another label,skills listandskills searchprintfetched 0001-01-01T00:00:00Z. No source does this today, but onmaintheIsZero()branch andTestProvenanceLineOmitsUnknownFetchTimeprevented it.readProvenanceincmd/skills/read.go:140has the same label check. Keep the bundled wording forBundledLabel, and also keep anIsZero()branch that leaves out the fetch time. Add back a test for a zero time with another label.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Restored an IsZero() branch in both provenanceLine and readProvenance so a non-bundled stale catalog with an unknown fetch time omits the fetch time, and added TestProvenanceLineOmitsUnknownFetchTime.