mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
* test(install): reproduce loss of pulled tracked records Exercise the two-machine push and pull sequence and reconciliation states so missing tracked clones cannot silently erase shared install intent. * fix(reconcile): preserve tracked records missing local clones Pull transfers tracked repository metadata but not ignored clones. Keep the missing records during global reconciliation so another install and push cannot erase shared intent or accepted audit findings on every machine. * test(reconcile): isolate tracked record fixtures Use the shared sandbox fixture for both reconciliation tests so their home and configuration paths remain isolated from the invoking environment. * fix(reconcile): retain all sourced tracked declarations Legacy tracked members and unfollowed source links can hide declarations from the local walk. Preserve sourced tracked records regardless of their path so unrelated installs cannot erase them or their audit acceptances. Document restoring a missing checkout before uninstalling it and cover migration, link collisions, aliases, and explicit removal. * test(reconcile): drop fixtures existing tests already pin The tracked-record unit test also seeded a missing plain record and a live plain record. TestReconcileGlobalSkills_PrunesStaleEntries already pins both outcomes: a sourced plain record whose folder is gone is pruned, and one on disk survives. The tracked record with no source still catches a fix that keeps everything or skips the prune. The two-machine test passed HOME and SKILLSHARE_CONFIG to RunCLIEnv, which already sets both from the sandbox for each child process. Separate homes, XDG paths, client overrides and git config remain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test(reconcile): retain tracked entry for unavailable link Expect sourced tracked declarations to survive reconciliation with either source-link policy, so the test matches the cross-machine retention contract. * fix(config): prune legacy tracked members Retain only sourced tracked repository declarations during reconciliation. Migrated member records are not restorable as repositories and retaining them would leave permanent misleading install requests and audit acceptances. * fix(reconcile): preserve tracked intent across followed links A source link can exist before a tracked repository declaration is pulled. Preserve that declaration when the linked folder is not a checkout so later reconciliation does not discard its record and audit acceptances. * test(reconcile): cover grouped followed declarations A followed group can contain the path of a pulled legacy repository declaration, which must retain its tracked intent while its key migrates. * fix(test): scope collision fixture runner correctly Keep the isolated CLI runner in the collision subtest that uses it so the integration test package can compile. * docs(manifest): clarify tracked checkout recovery A retained declaration cannot restore a checkout while another folder or source link occupies its destination, and restoration requires a reachable source. State those prerequisites in each manifest translation. * fix(config): prune members under recorded repositories A migrated underscore-named member can otherwise survive a missing checkout as a repository declaration. Check recorded ancestor paths while preserving ambiguous grouped declarations and unrelated aliases. * docs(manifest): restore fresh-clone project guidance Explain that project declarations without local install records remain available so teammates can install them after cloning. * refactor(reconcile): drop the tracked-intent walker policy Restore baseline normalization for present paths while retaining absent repository declarations through the shared metadata predicate. Isolate the reconcile fixtures without building a CLI and share native-client overrides without changing the original two-machine record and audit regression. Validation: gofmt, git diff --check and context-router check only. Runtime, builds and tests were not executed under the source-only gate. * fix: forget linked checkout records and declarations without checkouts Extend the metadata and uninstall owners to remove a declaration without reading or moving its occupant, contacting its source, or changing trash and gitignore. A failed metadata save makes every metadata-only result fail. Clean up global unlink records in CLI and API, preserve existing-path name precedence, report record-only results truthfully, and list declarations in the dashboard API with noCheckout. Keep project removal behavior unchanged. Remove the obsolete grouped-link walker-policy assertion while preserving grouped absent declarations and the original record/audit A/B regression. Validation: source-only five-pass review, gofmt, git diff --check and the context-router check. No runtime, builds, tests or frontend tooling ran. Stop at commit 15 for the mandatory Luna checkpoint before UI and docs work. * fix(server): reload metadata before removing declarations Preserve CLI records and audit acceptances written while the dashboard is open. Resolve new declarations from disk and refuse stale-cache saves after a reload failure, retaining unlink success when its link already moved. * feat(dashboard): remove a tracked repository record without a checkout Show declaration-only rows without checkout actions or status promises. Reuse Uninstall with record-specific confirmation and feedback, keep real-checkout force handling, and refresh the missing-entry list after repository removal or unlink. * docs: explain kept declarations and how to remove them Document direct global declaration removal and optional restore in English and all four translations, including occupied paths and normalization after reconcile. Keep built-in guidance accurate and use the existing API removal result for dashboard success feedback after concurrent CLI changes. * fix(dashboard): confirm restored checkouts after forceable refusals A tracked declaration can be restored through the CLI while its dashboard row still says there is no checkout. Treat a forceable uninstall refusal as evidence of the current checkout and promote the existing confirmation to its dirty or unreadable-status warning before allowing explicit force. Author stale-row regressions for both forceable codes before the source repair, and retain nonforceable failure and actual-result success feedback. Validation: five serial source review passes, git diff --check, and the context-router check. Tests, builds, runtime and frontend tooling were not run under the source-only gate. * test(server): persist overview declarations before routed request The overview fixture added declarations only to the in-memory skills store, which the real request's config reload replaced with on-disk metadata. The hosted unit, offline, and Nix jobs consequently returned no tracked rows. Save the complete fixture through MetadataStore before serving the request and fail setup on a save error. Keep the middleware, assertions, and production behavior unchanged. * fix(server): prefer exact declarations before checkout shorthand Removing a missing _team declaration from the dashboard could resolve the different org/_team checkout by basename and trash it instead. Reload metadata before declaration lookup, give exact declarations priority, and preserve checkout resolution before non-exact declaration fallback. Add routed absent/occupied regressions and checkout precedence guards, and persist existing checkout fixtures so the metadata reload keeps their state. Validation: gofmt, git diff --check, and context-router check passed. Tests were authored but not run under the source-only fleet restriction. * fix: preserve removal intent and report partial failures Bind dashboard record-only removal to its canonical declaration and refuse restored checkouts before checkout resolution or force. Refresh the row and require another confirmation before moving a restored checkout to trash. Keep unresolved uninstall inputs and their reasons in JSON failed results, including all-invalid requests, partial successes and dry runs. Report unlink metadata cleanup failures as partial results, refresh completed unlinks and show localized warnings. Keep CLI and dashboard guidance aligned. Regression tests were authored before source changes and remain unrun under the source-only task restriction. Static formatting, diff and router checks passed; no build, product runtime, frontend tooling or test suite was run. * fix(unlink): log partial metadata cleanup failures Write the unlink result after global metadata cleanup so load and save failures retain their diagnostic and report partial success. Preserve the successful link removal, warning, target and exit policy, and the existing link, project unlink and native removal failure behavior. Add the corrupt-metadata regression before the fix; leave it unrun under the source-only authorization. Formatting, diff and context-router checks pass; runtime verification remains with the coordinator. * fix(unlink): forget records below the removed link name Reconcile can normalize a followed link's record to untracked, and linked collections can retain nested repository declarations. Clean the removed namespace through the existing metadata path owner in both unlink callers, including audit acceptances, while keeping declaration uninstall strict. Author CLI and route regressions before the source fix for normalized and nested records, sibling preservation, and subsequent bare install. Tests remain unrun under the source-only task restriction; static checks only. * fix(uninstall): refuse a restored checkout at execution A declaration selected while absent can become a checkout before removal runs. Recheck the resolved source-relative name in the shared metadata-only execution owner and refuse before touching metadata, regardless of force. Reuse the existing dashboard conflict response and refresh/reselection flow for this refusal, preserving the earlier record-only intent guard. CLI results already carry shared execution failures through text and JSON. Author restoration, force, absent/occupied control and client boundary regressions before production edits. Correct the unlink fixture name and response-key assertion found in serial static review. All tests remain unrun under the source-only restriction; formatting/diff/router checks pass. * refactor(server): consolidate repository uninstall result handling Resolve a declaration or checkout to one item and canonical name before using the existing uninstall, conflict, log and success response tail. Keep metadata-only removal unforced, preserve its error and cache recovery behavior, and report movedToTrash from the selected item. Preserve exact declaration precedence, record-only checkout refusals, ordinary checkout errors and project behavior without changing tests. Five serial source review passes, gofmt, diff checks and the context-router check completed. Tests and builds remain unrun under the source-only brief. * fix(unlink): preserve independent records and trash undo metadata Limit unlink's legacy group matching to members so a retained declaration such as team/_repo survives unlinking _team. Share snapshot and removal matching while keeping generic uninstall's legacy contract unchanged. Save the exact removed records, audit acceptances and target overrides through uninstall's existing trash sidecar owner before pruning metadata. Keep metadata on sidecar failure and preserve completed-unlink warnings, fresh reloads, cache refresh and project-mode behavior. Author owner, CLI and API regressions for namespace collisions, undo, partial failures and project/empty controls. Source-only verification: gofmt, diff check and context-router check passed; runtime tests, builds, frontend checks and final make check remain unrun for root-owned gates. * fix(install): preserve independent tracked declarations Limit declaration-only cleanup to the precise namespace and legacy members already used by unlink. Keep independently installed prefixed repositories, their audit acceptances, and overrides when forgetting a missing checkout. * fix(cli): explain missing tracked repository recovery by mode Offer global record removal when restoring an unreachable source is unwanted. Keep project recovery scoped to install -p, share the hint with doctor, and align update documentation in every existing locale. * refactor(uninstall): share declaration and unlink operations Keep declaration resolution and unlink metadata ordering in shared owners so CLI and API preserve the same scope and recovery behavior. Consolidate domain regressions while retaining caller translation coverage. Distinguish record-only removals in API and CLI operation logs and CLI JSON, including mixed batches and dry runs. Document outcome fields, warning semantics, and current API error codes across existing locales. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Willie <egg358358@gmail.com>
331 lines
13 KiB
Go
331 lines
13 KiB
Go
//go:build !online
|
|
|
|
package integration
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"reflect"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/oplog"
|
|
"skillshare/internal/testutil"
|
|
"skillshare/internal/utils"
|
|
)
|
|
|
|
// linkSandbox holds a checkout with one skill outside the source.
|
|
func linkSandbox(t *testing.T) (*testutil.Sandbox, string) {
|
|
t.Helper()
|
|
sb := testutil.NewSandbox(t)
|
|
checkout := filepath.Join(sb.Root, "code", "dev-skills")
|
|
sb.WriteFile(filepath.Join(checkout, "foo", "SKILL.md"), "---\nname: foo\n---\n# foo")
|
|
return sb, checkout
|
|
}
|
|
|
|
func TestLink_EnableThenListShowsLinkedSkills(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
result := sb.RunCLI("link", checkout, "--enable")
|
|
result.AssertSuccess(t)
|
|
result.AssertOutputContains(t, "Linked _dev-skills")
|
|
if !utils.IsSymlinkOrJunction(filepath.Join(sb.SourcePath, "_dev-skills")) {
|
|
t.Fatal("link not created")
|
|
}
|
|
if got := sb.ReadFile(sb.ConfigPath); !contains(got, "follow_source_links: true") {
|
|
t.Fatalf("config not enabled:\n%s", got)
|
|
}
|
|
sb.RunCLI("list", "--json").AssertOutputContains(t, `"relPath": "_dev-skills/foo"`)
|
|
}
|
|
|
|
func TestLink_EnableFailureRollsBackLink(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
if err := os.Chmod(sb.ConfigPath, 0444); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { os.Chmod(sb.ConfigPath, 0644) })
|
|
if f, err := os.OpenFile(sb.ConfigPath, os.O_WRONLY, 0); err == nil {
|
|
f.Close()
|
|
t.Skip("requires file write permissions to be enforced")
|
|
}
|
|
|
|
result := sb.RunCLI("link", checkout, "--enable")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "failed to enable follow_source_links")
|
|
if _, err := os.Lstat(filepath.Join(sb.SourcePath, "_dev-skills")); !os.IsNotExist(err) {
|
|
t.Fatalf("link left behind after enable failure: %v", err)
|
|
}
|
|
if !sb.FileExists(filepath.Join(checkout, "foo", "SKILL.md")) {
|
|
t.Fatal("rollback touched the target")
|
|
}
|
|
}
|
|
|
|
func TestLink_WithoutEnablePrintsDoctorHint(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
|
|
result := sb.RunCLI("link", checkout, "--name", "_mine")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "_mine: not followed by discovery; its contents are invisible to skillshare. Set follow_source_links: true to follow it")
|
|
if contains(sb.ReadFile(sb.ConfigPath), "follow_source_links") {
|
|
t.Fatal("config changed without --enable")
|
|
}
|
|
}
|
|
|
|
func TestLink_RefusesTargetInsideSource(t *testing.T) {
|
|
sb, _ := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
sb.CreateSkill("local", map[string]string{"SKILL.md": "---\nname: local\n---\n# local"})
|
|
|
|
result := sb.RunCLI("link", filepath.Join(sb.SourcePath, "local"))
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "target is inside the source")
|
|
result = sb.RunCLI("link", filepath.Dir(sb.SourcePath), "--name", "_up")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "target is the source or a parent of it")
|
|
if sb.FileExists(filepath.Join(sb.SourcePath, "_local")) || sb.FileExists(filepath.Join(sb.SourcePath, "_up")) {
|
|
t.Fatal("refused link was created")
|
|
}
|
|
}
|
|
|
|
func TestLink_RefusesTargetOverlappingSyncTarget(t *testing.T) {
|
|
sb, _ := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
target := sb.CreateTarget("claude")
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets:\n claude:\n path: " + target + "\n")
|
|
|
|
result := sb.RunCLI("link", filepath.Dir(target), "--name", "_claude")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "target overlaps sync target")
|
|
if sb.FileExists(filepath.Join(sb.SourcePath, "_claude")) {
|
|
t.Fatal("refused link was created")
|
|
}
|
|
}
|
|
|
|
func TestLink_WarnsWhenTargetIsNotCheckout(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\nfollow_source_links: true\ntargets: {}\n")
|
|
|
|
result := sb.RunCLI("link", checkout)
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "target is not a git checkout")
|
|
|
|
if err := os.Mkdir(filepath.Join(checkout, ".git"), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
result = sb.RunCLI("link", checkout, "--name", "_again")
|
|
result.AssertSuccess(t)
|
|
result.AssertOutputNotContains(t, "not a git checkout")
|
|
}
|
|
|
|
func TestUnlink_OptionTerminator(t *testing.T) {
|
|
for _, name := range []string{"-local", "-g", "-p"} {
|
|
t.Run(name, func(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
sb.RunCLIInDir(sb.Root, "link", checkout).AssertSuccess(t)
|
|
if err := os.Rename(filepath.Join(sb.SourcePath, "_dev-skills"), filepath.Join(sb.SourcePath, name)); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
sb.RunCLIInDir(sb.Root, "unlink", "--global", "--", name).AssertSuccess(t)
|
|
if _, err := os.Lstat(filepath.Join(sb.SourcePath, name)); !os.IsNotExist(err) {
|
|
t.Fatalf("link still present: %v", err)
|
|
}
|
|
if !sb.FileExists(filepath.Join(checkout, "foo", "SKILL.md")) {
|
|
t.Fatal("unlink touched the target")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestLink_HelpWithoutConfig(t *testing.T) {
|
|
sb := testutil.NewSandbox(t)
|
|
defer sb.Cleanup()
|
|
os.Remove(sb.ConfigPath)
|
|
for _, args := range [][]string{{"link", "-h"}, {"link", "--help", "-p"}, {"unlink", "--help"}} {
|
|
result := sb.RunCLIInDir(sb.Root, args...)
|
|
result.AssertSuccess(t)
|
|
result.AssertOutputContains(t, "Usage")
|
|
}
|
|
if _, err := os.Stat(sb.ConfigPath); !os.IsNotExist(err) {
|
|
t.Fatalf("help created a config: %v", err)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(sb.Root, ".skillshare")); !os.IsNotExist(err) {
|
|
t.Fatalf("help created a project config: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestLink_NameValueLooksLikeModeFlag(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
sb.RunCLI("link", checkout, "--name", "-g").AssertSuccess(t)
|
|
if !utils.IsSymlinkOrJunction(filepath.Join(sb.SourcePath, "-g")) {
|
|
t.Fatal("link -g not created")
|
|
}
|
|
}
|
|
|
|
func TestLink_OptionTerminatorPath(t *testing.T) {
|
|
sb, _ := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
checkout := filepath.Join(sb.Root, "-checkout")
|
|
sb.WriteFile(filepath.Join(checkout, "foo", "SKILL.md"), "---\nname: foo\n---\n# foo")
|
|
cwd := sb.Root
|
|
if runtime.GOOS != "windows" {
|
|
// Preserve coverage for a path reached through a symlinked working directory.
|
|
cwd = filepath.Join(filepath.Dir(sb.Root), "root-alias")
|
|
sb.CreateSymlink(sb.Root, cwd)
|
|
}
|
|
sb.RunCLIInDir(cwd, "link", "--global", "--", "-checkout").AssertSuccess(t)
|
|
if got, err := filepath.EvalSymlinks(filepath.Join(sb.SourcePath, "_-checkout")); err != nil || got != checkout {
|
|
t.Fatalf("link target = %q, %v; want %s", got, err, checkout)
|
|
}
|
|
}
|
|
|
|
func TestLink_ProjectUsesProjectSourceAndTargets(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
projectRoot := sb.SetupProjectDir("claude")
|
|
source := filepath.Join(projectRoot, ".skillshare", "skills")
|
|
|
|
result := sb.RunCLIInDir(projectRoot, "link", filepath.Join(projectRoot, ".claude"), "--name", "_claude", "-p")
|
|
result.AssertFailure(t)
|
|
result.AssertAnyOutputContains(t, "target overlaps sync target")
|
|
|
|
sb.RunCLIInDir(projectRoot, "link", checkout, "--enable", "-p").AssertSuccess(t)
|
|
if !utils.IsSymlinkOrJunction(filepath.Join(source, "_dev-skills")) {
|
|
t.Fatal("link not created in the project source")
|
|
}
|
|
if got := sb.ReadFile(filepath.Join(projectRoot, ".skillshare", "config.yaml")); !contains(got, "follow_source_links: true") {
|
|
t.Fatalf("project config not enabled:\n%s", got)
|
|
}
|
|
sb.RunCLIInDir(projectRoot, "unlink", "_dev-skills", "-p").AssertSuccess(t)
|
|
if sb.FileExists(filepath.Join(source, "_dev-skills")) || !sb.FileExists(filepath.Join(checkout, "foo", "SKILL.md")) {
|
|
t.Fatal("project unlink did not remove only the link")
|
|
}
|
|
}
|
|
|
|
func TestUnlink_MetadataReloadFailureLogsPartial(t *testing.T) {
|
|
sb, checkout := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
run := func(args ...string) *testutil.Result { return sb.RunCLIEnv(sb.MachineEnv(), args...) }
|
|
run("link", checkout, "-g").AssertSuccess(t)
|
|
invalid := "invalid metadata from interrupted external write"
|
|
sb.WriteFile(install.MetadataPath(sb.SourcePath), invalid)
|
|
|
|
result := run("unlink", "_dev-skills", "-g")
|
|
result.AssertSuccess(t)
|
|
result.AssertOutputContains(t, "Unlinked _dev-skills")
|
|
result.AssertAnyOutputContains(t, "Unlinked, but could not update metadata")
|
|
entries, err := oplog.Read(sb.ConfigPath, oplog.OpsFile, 1)
|
|
if err != nil || len(entries) != 1 || entries[0].Command != "unlink" || entries[0].Status != "partial" ||
|
|
!strings.Contains(entries[0].Message, "Unlinked, but could not update metadata: failed to parse metadata") {
|
|
t.Fatalf("partial unlink log: %+v %v", entries, err)
|
|
}
|
|
if _, err := os.Lstat(filepath.Join(sb.SourcePath, "_dev-skills")); !os.IsNotExist(err) {
|
|
t.Fatalf("link still exists: %v", err)
|
|
}
|
|
if !sb.FileExists(filepath.Join(checkout, "foo", "SKILL.md")) {
|
|
t.Fatal("unlink touched the target")
|
|
}
|
|
if got := sb.ReadFile(install.MetadataPath(sb.SourcePath)); got != invalid {
|
|
t.Fatalf("reload failure overwrote metadata: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestUnlink_SidecarFailureLogsPartialAndKeepsMetadata(t *testing.T) {
|
|
sb, target := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
run := func(args ...string) *testutil.Result { return sb.RunCLIEnv(sb.MachineEnv(), args...) }
|
|
// The link plus timestamp fits a filesystem component; its sidecar does not.
|
|
name := "_" + strings.Repeat("n", 229)
|
|
run("link", target, "--name", name, "-g").AssertSuccess(t)
|
|
store := install.NewMetadataStore()
|
|
store.Set(name, &install.MetadataEntry{Source: "normalized"})
|
|
store.AuditAccepted = map[string][]string{name + "/foo": {"accepted"}}
|
|
store.SetTargetOverride(name+"/foo", nil)
|
|
if err := store.Save(sb.SourcePath); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
before := sb.ReadFile(install.MetadataPath(sb.SourcePath))
|
|
result := run("unlink", name, "-g")
|
|
result.AssertSuccess(t)
|
|
result.AssertAnyOutputContains(t, "failed to save its metadata")
|
|
entries, err := oplog.Read(sb.ConfigPath, oplog.OpsFile, 1)
|
|
if err != nil || len(entries) != 1 || entries[0].Status != "partial" || !strings.Contains(entries[0].Message, "Unlinked, but could not update metadata") {
|
|
t.Fatalf("sidecar failure not logged as partial: %+v %v", entries, err)
|
|
}
|
|
if _, err := os.Lstat(filepath.Join(sb.SourcePath, name)); !os.IsNotExist(err) || sb.ReadFile(install.MetadataPath(sb.SourcePath)) != before || !sb.FileExists(filepath.Join(target, "foo", "SKILL.md")) {
|
|
t.Fatalf("partial unlink damaged link metadata or referent: %v", err)
|
|
}
|
|
}
|
|
|
|
// Cross-package flow: reconcile each link kind, unlink, undo, then ensure bare
|
|
// install does not recreate the removed declaration. Metadata matching is
|
|
// owned by install; persistence and exact undo are owned by uninstall.
|
|
func TestUnlink_ReconciledRecordsRoundTrip(t *testing.T) {
|
|
for _, kind := range []string{"normalized", "checkout", "nested"} {
|
|
t.Run(kind, func(t *testing.T) {
|
|
sb, target := linkSandbox(t)
|
|
defer sb.Cleanup()
|
|
sb.WriteConfig("source: " + sb.SourcePath + "\ntargets: {}\n")
|
|
for key, value := range sb.MachineEnv() {
|
|
t.Setenv(key, value)
|
|
}
|
|
run := func(args ...string) *testutil.Result { return sb.RunCLIEnv(sb.MachineEnv(), args...) }
|
|
rel := "_dev-skills"
|
|
store := install.NewMetadataStore()
|
|
checkout := target
|
|
if kind == "nested" {
|
|
rel += "/_team"
|
|
checkout = filepath.Join(target, "_team")
|
|
sb.WriteFile(filepath.Join(checkout, "SKILL.md"), "# nested")
|
|
}
|
|
if kind == "normalized" {
|
|
store.Set(rel, &install.MetadataEntry{Source: "file:///nonexistent/team.git", Tracked: true})
|
|
} else {
|
|
testutil.RunGit(t, checkout, "init")
|
|
testutil.RunGit(t, checkout, "remote", "add", "origin", "file:///nonexistent/team.git")
|
|
}
|
|
if err := store.Save(sb.SourcePath); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
run("link", target, "--enable", "-g").AssertSuccess(t)
|
|
other := filepath.Join(sb.Root, "other")
|
|
sb.WriteFile(filepath.Join(other, "SKILL.md"), "---\nname: other\n---\n# other\n")
|
|
run("install", other, "-g").AssertSuccess(t)
|
|
store, err := install.LoadMetadata(sb.SourcePath)
|
|
if err != nil || store.Get(rel) == nil || store.Get(rel).Tracked != (kind != "normalized") {
|
|
t.Fatalf("reconcile record: %+v %v", store, err)
|
|
}
|
|
run("unlink", "_dev-skills", "-g").AssertSuccess(t)
|
|
run("trash", "restore", "_dev-skills", "-g").AssertSuccess(t)
|
|
restored, err := install.LoadMetadata(sb.SourcePath)
|
|
if err != nil || !reflect.DeepEqual(restored.Get(rel), store.Get(rel)) {
|
|
t.Fatalf("record round trip: %+v %v", restored, err)
|
|
}
|
|
run("unlink", "_dev-skills", "-g").AssertSuccess(t)
|
|
run("install", "-g").AssertSuccess(t)
|
|
if _, err := os.Lstat(filepath.Join(sb.SourcePath, "_dev-skills")); !os.IsNotExist(err) {
|
|
t.Fatalf("bare install resurrected link: %v", err)
|
|
}
|
|
if got := sb.ReadFile(filepath.Join(target, "foo", "SKILL.md")); got != "---\nname: foo\n---\n# foo" {
|
|
t.Fatalf("referent changed: %q", got)
|
|
}
|
|
})
|
|
}
|
|
}
|