feat(profiles): registry + provisioning ×3
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Profiles S1 (#134, ADR-0014): one gate pass provisions all three surface profiles — museion adopted in place (never reconfigured; its glm-5.3-max stays the user's), museion-pass1/-pass2 created fresh with the #132 sonnet defaults + 24k budget via the hermes 'config set' CLI rail, marker-gated so a re-pass is a no-op and Settings changes survive; a failed provision names the profile on the #48 card. Skills move to ONE master copy under Application Support, symlinked per profile per the #133 allocation (P1 9 · P2 8 · Chat 10); copy-era dirs migrate on byte-match (.DS_Store-tolerant, symlink-refusing), diverged dirs stay copies, user skills untouched (G3a). Backup widens to one three-subdir stamp, any-live-skip-all; RESTORE.md names the three folders. Two review rounds (standards+spec, then finish-audit ponytail/ security/general) caught and fixed: the dead .DS_Store leniency in treesByteMatch, exit-code-only config-set trust, the swallowed marker write (defaults-stomp re-arm), symlink-following in the untrusted tree, and a fixture-skewed count pin. Suite: 412 passed / 414 (fork flake green in isolation 16/16; UI launch = pre-existing testmanagerd flake, failed identically pre-change). DOX: Museion/AGENTS.md, MuseionTests/AGENTS.md, ref/writing skills/AGENTS.md rewritten. Closes #134
This commit is contained in:
1 parent
2032534305
commit
610f8789bd
15 files changed
+1292
-232
No files matched your search
@@ -3,9 +3,9 @@
|
||||
// MuseionTests
|
||||
//
|
||||
// Exercises the real Process path with a fake hermes binary and injected
|
||||
// profile/payload dirs (#47) — same pattern as EngineGateTests.
|
||||
// profile/payload/master dirs (#47, #134) — same pattern as EngineGateTests.
|
||||
//
|
||||
// Convention: the fake creates the profile at `<binaryDir>/profiles/<name>`
|
||||
// Convention: the fake creates profiles at `<binaryDir>/profiles/<name>`
|
||||
// (derived from its own path — race-free under parallel tests), so each test
|
||||
// passes `profileRoot = binaryDir + "/profiles"`.
|
||||
//
|
||||
@@ -26,13 +26,18 @@ struct SeedSkill {
|
||||
/// stdout, exit 1 (the create race). fail: "Error: create exploded", exit 1.
|
||||
/// stderr-only: error on stderr with empty stdout (#48 fallback).
|
||||
///
|
||||
/// Also speaks `mcp` behind the `-p museion` global flag (#23): `mcp list`
|
||||
/// prints "museion-tools" iff `<binaryDir>/mcp-registered` exists, else
|
||||
/// "No MCP servers configured."; `mcp add` verifies its argv, reads ONE "y"
|
||||
/// line from stdin (mismatch/EOF → "Cancelled.", exit 1 — nothing saved),
|
||||
/// records the exact invocation in `<binaryDir>/mcp-add-invocation`, drops the
|
||||
/// marker, prints "Saved 'museion-tools' to …" (verified wire strings).
|
||||
/// `<binaryDir>/mcp-add-fails` forces "Error: mcp add exploded", exit 1.
|
||||
/// Also speaks `mcp` and `config set` behind the `-p <profile>` global flag
|
||||
/// (#23, #134): `mcp list` prints "museion-tools" iff
|
||||
/// `<binaryDir>/mcp-registered-<profile>` exists, else "No MCP servers
|
||||
/// configured."; `mcp add` verifies its argv, reads ONE "y" line from stdin
|
||||
/// (mismatch/EOF → "Cancelled.", exit 1 — nothing saved), records the exact
|
||||
/// invocation in `<binaryDir>/mcp-add-invocation-<profile>`, drops the
|
||||
/// per-profile marker, prints "Saved 'museion-tools' to …" (verified wire
|
||||
/// strings). `config set <key> <value> [--force]` appends the exact argv to
|
||||
/// `<binaryDir>/config-set-<profile>` and prints the verified "✓ Set …" line.
|
||||
/// `<binaryDir>/mcp-add-fails` / `config-set-fails` force the matching
|
||||
/// failure. Every `profile create` name appends to
|
||||
/// `<binaryDir>/profile-create-log`.
|
||||
func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> String {
|
||||
let path = (dir as NSString).appendingPathComponent(name)
|
||||
let createBlock = switch mode {
|
||||
@@ -63,11 +68,13 @@ func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> St
|
||||
#!/bin/zsh
|
||||
if [[ "$1" == "profile" && "$2" == "create" ]]; then
|
||||
NAME="$3"
|
||||
print -r -- "$NAME" >> "${0:h}/profile-create-log"
|
||||
\(createBlock)
|
||||
fi
|
||||
if [[ "$1" == "-p" && "$2" == "museion" && "$3" == "mcp" ]]; then
|
||||
if [[ "$1" == "-p" && "$3" == "mcp" ]]; then
|
||||
PROFILE="$2"
|
||||
if [[ "$4" == "list" ]]; then
|
||||
if [[ -f "${0:h}/mcp-registered" ]]; then
|
||||
if [[ -f "${0:h}/mcp-registered-$PROFILE" ]]; then
|
||||
print "museion-tools enabled"
|
||||
exit 0
|
||||
fi
|
||||
@@ -88,12 +95,22 @@ func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> St
|
||||
print "Cancelled."
|
||||
exit 1
|
||||
fi
|
||||
print -r -- "$*" > "${0:h}/mcp-add-invocation"
|
||||
touch "${0:h}/mcp-registered"
|
||||
print "Saved 'museion-tools' to ${0:h}/profiles/museion/config.yaml"
|
||||
print -r -- "$*" > "${0:h}/mcp-add-invocation-$PROFILE"
|
||||
touch "${0:h}/mcp-registered-$PROFILE"
|
||||
print "Saved 'museion-tools' to ${0:h}/profiles/$PROFILE/config.yaml"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [[ "$1" == "-p" && "$3" == "config" && "$4" == "set" ]]; then
|
||||
PROFILE="$2"
|
||||
if [[ -f "${0:h}/config-set-fails" ]]; then
|
||||
print "Error: config set exploded"
|
||||
exit 1
|
||||
fi
|
||||
print -r -- "$*" >> "${0:h}/config-set-$PROFILE"
|
||||
print "✓ Set $5 = $6 in ${0:h}/profiles/$PROFILE/config.yaml"
|
||||
exit 0
|
||||
fi
|
||||
exit 97
|
||||
"""
|
||||
try? FileManager.default.createDirectory(atPath: dir, withIntermediateDirectories: true)
|
||||
@@ -125,7 +142,8 @@ func makePayload(at dir: String, skills: [SeedSkill]) -> String {
|
||||
"""
|
||||
try? skillMarkdown.write(
|
||||
toFile: (skillDir as NSString).appendingPathComponent("SKILL.md"),
|
||||
atomically: true, encoding: .utf8,
|
||||
atomically: true,
|
||||
encoding: .utf8,
|
||||
)
|
||||
}
|
||||
// Non-skill extras that must never seed (the repo's AGENTS.md, the manifest).
|
||||
@@ -140,8 +158,8 @@ func provTempDir(_ label: String) -> String {
|
||||
return dir
|
||||
}
|
||||
|
||||
func skillPath(_ profileRoot: String, _ name: String) -> String {
|
||||
((profileRoot as NSString).appendingPathComponent("museion/skills") as NSString).appendingPathComponent(name)
|
||||
func skillPath(_ profileRoot: String, _ profile: String, _ name: String) -> String {
|
||||
((profileRoot as NSString).appendingPathComponent("\(profile)/skills") as NSString).appendingPathComponent(name)
|
||||
}
|
||||
|
||||
func readSkillBody(_ path: String) -> String {
|
||||
@@ -162,45 +180,57 @@ struct ProfileProvisionerTests {
|
||||
let binDir = provTempDir("fresh")
|
||||
let binary = makeFakeHermes(at: binDir, mode: "ok")
|
||||
let profileRoot = (binDir as NSString).appendingPathComponent("profiles")
|
||||
let master = provTempDir("master")
|
||||
let outcome = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
masterRoot: master,
|
||||
)
|
||||
#expect(outcome == .seeded(copied: 2, present: 0))
|
||||
#expect(FileManager.default.fileExists(atPath: skillPath(profileRoot, "serif-writing")))
|
||||
#expect(readSkillBody(skillPath(profileRoot, "deslop")).contains("tell catalog"))
|
||||
// #134: 2 master copies + one symlink per skill per profile (×3).
|
||||
#expect(outcome == .seeded(copied: 8, present: 0))
|
||||
#expect(FileManager.default.fileExists(atPath: skillPath(profileRoot, "museion", "serif-writing")))
|
||||
#expect(readSkillBody(skillPath(profileRoot, "museion-pass1", "deslop")).contains("tell catalog"))
|
||||
#expect(FileManager.default.fileExists(atPath: skillPath(profileRoot, "museion-pass2", "serif-writing")))
|
||||
}
|
||||
|
||||
@Test func `already-exists exit 1 is success and profile is left intact`() {
|
||||
let binDir = provTempDir("exists")
|
||||
let profileRoot = (binDir as NSString).appendingPathComponent("profiles")
|
||||
let binary = makeFakeHermes(at: binDir, mode: "exists")
|
||||
let master = provTempDir("master")
|
||||
let payload = makePayload(at: provTempDir("payload"), skills: skills)
|
||||
_ = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload)
|
||||
// Writer-modified skill in place — second pass must never overwrite it.
|
||||
_ = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload, masterRoot: master)
|
||||
// Writer-modified skill in place — the next pass must never overwrite
|
||||
// it (G3a: through a linked skill the edit lands in the shared
|
||||
// master, which seeding never touches).
|
||||
try? "mentor's own edits".write(
|
||||
toFile: (skillPath(profileRoot, "serif-writing") as NSString).appendingPathComponent("SKILL.md"),
|
||||
atomically: true, encoding: .utf8,
|
||||
toFile: (skillPath(profileRoot, "museion", "serif-writing") as NSString).appendingPathComponent("SKILL.md"),
|
||||
atomically: true,
|
||||
encoding: .utf8,
|
||||
)
|
||||
let outcome = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload)
|
||||
#expect(outcome == .seeded(copied: 0, present: 2))
|
||||
#expect(readSkillBody(skillPath(profileRoot, "serif-writing")) == "mentor's own edits")
|
||||
let outcome = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload, masterRoot: master)
|
||||
// Master 2 present; museion 2 links; pass profiles 2 links each —
|
||||
// nothing new, nothing overwritten.
|
||||
#expect(outcome == .seeded(copied: 0, present: 8))
|
||||
#expect(readSkillBody(skillPath(profileRoot, "museion", "serif-writing")) == "mentor's own edits")
|
||||
}
|
||||
|
||||
@Test func `later app version adds new skill without touching old ones`() {
|
||||
let binDir = provTempDir("upgrade")
|
||||
let profileRoot = (binDir as NSString).appendingPathComponent("profiles")
|
||||
let binary = makeFakeHermes(at: binDir, mode: "ok")
|
||||
let master = provTempDir("master")
|
||||
let payloadV1 = makePayload(at: provTempDir("p1"), skills: skills)
|
||||
_ = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payloadV1)
|
||||
_ = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payloadV1, masterRoot: master)
|
||||
let payloadV2 = makePayload(
|
||||
at: provTempDir("p2"),
|
||||
skills: skills + [SeedSkill(name: "rhetoric", version: "1.0", body: "persuasion")],
|
||||
)
|
||||
let outcome = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payloadV2)
|
||||
#expect(outcome == .seeded(copied: 1, present: 2))
|
||||
#expect(FileManager.default.fileExists(atPath: skillPath(profileRoot, "rhetoric")))
|
||||
let outcome = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payloadV2, masterRoot: master)
|
||||
// rhetoric joins the master (1 copy) and every profile's links (3).
|
||||
#expect(outcome == .seeded(copied: 4, present: 8))
|
||||
#expect(FileManager.default.fileExists(atPath: skillPath(profileRoot, "museion", "rhetoric")))
|
||||
}
|
||||
|
||||
@Test func `create failure reports phase-named excerpt`() {
|
||||
@@ -210,8 +240,10 @@ struct ProfileProvisionerTests {
|
||||
hermesBinary: binary,
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
#expect(outcome == .failed(phase: .create, excerpt: "Error: create exploded"))
|
||||
// Chat provisions first (#134 loop order) — its create failed.
|
||||
#expect(outcome == .failed(profile: "museion", phase: .create, excerpt: "Error: create exploded"))
|
||||
}
|
||||
|
||||
@Test func `create failure with empty stdout falls back to stderr`() {
|
||||
@@ -222,8 +254,9 @@ struct ProfileProvisionerTests {
|
||||
hermesBinary: binary,
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
#expect(outcome == .failed(phase: .create, excerpt: "Error: stderr-only boom"))
|
||||
#expect(outcome == .failed(profile: "museion", phase: .create, excerpt: "Error: stderr-only boom"))
|
||||
}
|
||||
|
||||
@Test func `manifest entry missing from payload is a copy failure`() {
|
||||
@@ -233,17 +266,21 @@ struct ProfileProvisionerTests {
|
||||
// Manifest names a dir the payload doesn't carry.
|
||||
try? "serif-writing\ndeslop\nrhetoric\n".write(
|
||||
toFile: (payload as NSString).appendingPathComponent("seed-manifest.txt"),
|
||||
atomically: true, encoding: .utf8,
|
||||
atomically: true,
|
||||
encoding: .utf8,
|
||||
)
|
||||
let outcome = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: payload,
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
guard case let .failed(phase, excerpt) = outcome else {
|
||||
// Master-level failure — before any profile, so no profile named.
|
||||
guard case let .failed(profile, phase, excerpt) = outcome else {
|
||||
Issue.record("expected copy failure, got \(outcome)")
|
||||
return
|
||||
}
|
||||
#expect(profile == nil)
|
||||
#expect(phase == .copy)
|
||||
#expect(excerpt.contains("rhetoric"))
|
||||
}
|
||||
@@ -257,17 +294,20 @@ struct ProfileProvisionerTests {
|
||||
for bad in ["../escape", "/tmp/evil", ".", ".."] {
|
||||
try? "serif-writing\n\(bad)\n".write(
|
||||
toFile: (payload as NSString).appendingPathComponent("seed-manifest.txt"),
|
||||
atomically: true, encoding: .utf8,
|
||||
atomically: true,
|
||||
encoding: .utf8,
|
||||
)
|
||||
let outcome = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: payload,
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
guard case let .failed(phase, excerpt) = outcome else {
|
||||
guard case let .failed(profile, phase, excerpt) = outcome else {
|
||||
Issue.record("'\(bad)' must fail the pass, got \(outcome)")
|
||||
continue
|
||||
}
|
||||
#expect(profile == nil)
|
||||
#expect(phase == .copy)
|
||||
#expect(excerpt.contains(bad))
|
||||
}
|
||||
@@ -281,91 +321,45 @@ struct ProfileProvisionerTests {
|
||||
hermesBinary: binary,
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: payload,
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
#expect(outcome == .failed(phase: .copy, excerpt: "seed-manifest.txt missing from payload"))
|
||||
#expect(outcome == .failed(profile: nil, phase: .copy, excerpt: "seed-manifest.txt missing from payload"))
|
||||
}
|
||||
|
||||
@Test func `non-manifest payload files never seed`() {
|
||||
let binDir = provTempDir("extras")
|
||||
let profileRoot = (binDir as NSString).appendingPathComponent("profiles")
|
||||
let binary = makeFakeHermes(at: binDir, mode: "ok")
|
||||
let master = provTempDir("master")
|
||||
_ = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
masterRoot: master,
|
||||
)
|
||||
let seededRoot = (profileRoot as NSString).appendingPathComponent("museion/skills")
|
||||
let seeded = (try? FileManager.default.contentsOfDirectory(atPath: seededRoot)) ?? []
|
||||
#expect(Set(seeded) == Set(["serif-writing", "deslop"]))
|
||||
let masterEntries = (try? FileManager.default.contentsOfDirectory(atPath: master)) ?? []
|
||||
#expect(Set(masterEntries) == Set(["serif-writing", "deslop"]))
|
||||
}
|
||||
|
||||
@Test func `orphaned temp dirs from an interrupted copy are swept`() {
|
||||
let binDir = provTempDir("orphan")
|
||||
let profileRoot = (binDir as NSString).appendingPathComponent("profiles")
|
||||
let binary = makeFakeHermes(at: binDir, mode: "ok")
|
||||
let master = provTempDir("master")
|
||||
let payload = makePayload(at: provTempDir("payload"), skills: skills)
|
||||
_ = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload)
|
||||
_ = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload, masterRoot: master)
|
||||
// Simulate an interrupted pass: the temp dir landed, the rename never ran.
|
||||
let skillsDir = (profileRoot as NSString).appendingPathComponent("museion/skills")
|
||||
let orphan = (skillsDir as NSString).appendingPathComponent(".serif-writing-DEADBEEF")
|
||||
try? FileManager.default.createDirectory(atPath: orphan, withIntermediateDirectories: true)
|
||||
let outcome = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload)
|
||||
#expect(outcome == .seeded(copied: 0, present: 2))
|
||||
let outcome = ProfileProvisioner.perform(hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload, masterRoot: master)
|
||||
#expect(outcome == .seeded(copied: 0, present: 8))
|
||||
#expect(!FileManager.default.fileExists(atPath: orphan))
|
||||
}
|
||||
|
||||
@Test func `fresh pass registers museion-tools via the cli with the exact command line`() {
|
||||
let binDir = provTempDir("mcp-add")
|
||||
let serverPath = (provTempDir("server") as NSString).appendingPathComponent("Museion")
|
||||
let outcome = ProfileProvisioner.perform(
|
||||
hermesBinary: makeFakeHermes(at: binDir, mode: "ok"),
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
serverBinaryPath: serverPath,
|
||||
)
|
||||
#expect(outcome == .seeded(copied: 2, present: 0))
|
||||
let invocation = ((try? String(
|
||||
contentsOfFile: (binDir as NSString).appendingPathComponent("mcp-add-invocation"),
|
||||
encoding: .utf8,
|
||||
)) ?? "").trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
#expect(invocation == "-p museion mcp add museion-tools --command \(serverPath) --args --serve-mcp")
|
||||
}
|
||||
|
||||
@Test func `already-registered profile skips the add`() {
|
||||
let binDir = provTempDir("mcp-skip")
|
||||
// Pre-existing registration → `mcp list` reports it → no add: a re-add
|
||||
// would prompt "Overwrite? [y/N]" — the skip avoids that branch.
|
||||
try? "".write(
|
||||
toFile: (binDir as NSString).appendingPathComponent("mcp-registered"),
|
||||
atomically: true,
|
||||
encoding: .utf8,
|
||||
)
|
||||
let outcome = ProfileProvisioner.perform(
|
||||
hermesBinary: makeFakeHermes(at: binDir, mode: "ok"),
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
serverBinaryPath: "/fake/Museon",
|
||||
)
|
||||
#expect(outcome == .seeded(copied: 2, present: 0))
|
||||
#expect(!FileManager.default.fileExists(atPath: (binDir as NSString).appendingPathComponent("mcp-add-invocation")))
|
||||
}
|
||||
|
||||
@Test func `rejected add fails the register phase with the cli excerpt`() {
|
||||
let binDir = provTempDir("mcp-reject")
|
||||
try? "".write(
|
||||
toFile: (binDir as NSString).appendingPathComponent("mcp-add-fails"),
|
||||
atomically: true,
|
||||
encoding: .utf8,
|
||||
)
|
||||
let outcome = ProfileProvisioner.perform(
|
||||
hermesBinary: makeFakeHermes(at: binDir, mode: "ok"),
|
||||
profileRoot: (binDir as NSString).appendingPathComponent("profiles"),
|
||||
payloadRoot: makePayload(at: provTempDir("payload"), skills: skills),
|
||||
serverBinaryPath: "/fake/Museion",
|
||||
)
|
||||
#expect(outcome == .failed(phase: .register, excerpt: "Error: mcp add exploded"))
|
||||
}
|
||||
|
||||
@Test func `bundled manifest matches bundled payload`() {
|
||||
// url(forResource:) doesn't resolve folder references — use the same path
|
||||
// the provisioner itself builds.
|
||||
@@ -405,12 +399,14 @@ struct ProfileProvisionerTests {
|
||||
hermesBinary: makeFakeHermes(at: binDir, name: "hermes-fail", mode: "fail"),
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: payload,
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
#expect(model.lastFailure != nil)
|
||||
await model.runPass(
|
||||
hermesBinary: makeFakeHermes(at: binDir, name: "hermes-ok", mode: "ok"),
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: payload,
|
||||
masterRoot: provTempDir("master"),
|
||||
)
|
||||
#expect(model.lastFailure == nil)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user