chore(lint): repo-wide green becomes the contract
CI / ci (push) Canceled after 0s
CI / ci (push) Canceled after 0s
Close the lint arc #194-#197: deliberate-style rule disables with rationales (#194), filter-safe test renames + --test-case-name-format preserve (#195), every surviving warning fixed through the sanctioned lint-stable shapes (#196), and the docs now state the true contract (#197): bare swiftlint . reports zero violations and swiftformat . reformats nothing, while push gates stay scoped to the push's own files (settled #190 design) — the pre-push hook's stale 'pre-existing violations' rationale blocks refreshed, gate logic untouched. Also in the sweep: quiesce the FSEvent-burst watcher race in LibrarySearchTests (two rescans double-count one shared PostScanCache miss; benign revision over-bump), pin the learnings scan's symlink-skip contract (flip-verified — defended in depth by the lstat guard AND contentsOfDirectory's own symlink refusal), reorder that scan's guard so cheap rejections precede the directory listing, and park the roster chmod window with a ceiling comment. Finish-audit: 3 reviewers, 0 blocking; the one code finding was disproved by probe (&& out-binds ?? — the guard was correct). Suite 693/693 via scripts/full-test.sh; swiftlint 0 violations; swiftformat 0/141; hook rig 23/23. Closes #197
This commit is contained in:
1 parent
0ab00eb7b6
commit
d7fd11cf0d
29 files changed
+549
-269
No files matched your search
@@ -12,6 +12,7 @@ Owned by the root AGENTS.md contract.
|
||||
|
||||
- Uses Swift Testing (`@Test`, `#expect`) — not XCTest.
|
||||
- Always give `@Suite` its string argument — bare `@Suite` is stripped by this repo's swiftformat.
|
||||
- `@Test` names: backticked sentence style is the convention; plain lowercase-camel identifiers are the deliberate exception where name-level `-only-testing` addressability matters (#195) — `.swiftformat` sets `--test-case-name-format preserve`, so both shapes are format-clean.
|
||||
- Imports `@testable import Museion`; app code is default-MainActor, so cross-actor tests need `@MainActor` or nonisolated declarations in app code.
|
||||
- Deployment target and versions follow the app target; leave `CURRENT_PROJECT_VERSION = 1` here.
|
||||
|
||||
|
||||
@@ -124,6 +124,25 @@ struct LearningsPaneTests {
|
||||
#expect(LearningsIndex.scan(home: home).isEmpty)
|
||||
}
|
||||
|
||||
/// Scenario: the skip posture Post.scan pins, on this scan — a symlinked
|
||||
/// type dir must not be followed. Defended in depth: the lstat guard
|
||||
/// (a symlink reports isDirectory=false) AND contentsOfDirectory's own
|
||||
/// refusal of a symlinked entry — flip-verified: the pin fails only when
|
||||
/// BOTH go traversal-shaped (fileExists guard + resolved-URL listing).
|
||||
@Test func `a symlinked type dir never surfaces`() throws {
|
||||
let home = try makeHome { home in
|
||||
try writeLearning(home, "posts", "20261021-one-real-entry.md", "# real\n")
|
||||
}
|
||||
let learnings = home.appendingPathComponent("learnings", isDirectory: true)
|
||||
try FileManager.default.createSymbolicLink(
|
||||
at: learnings.appendingPathComponent("linked", isDirectory: true),
|
||||
withDestinationURL: learnings.appendingPathComponent("posts", isDirectory: true),
|
||||
)
|
||||
let groups = LearningsIndex.scan(home: home)
|
||||
#expect(groups.map(\.type) == ["posts"]) // the link's alias never groups
|
||||
#expect(groups.flatMap(\.entries).count == 1) // its view of posts never doubles
|
||||
}
|
||||
|
||||
// MARK: Decay surface (#27, S4.2)
|
||||
|
||||
/// Scenario: Entry carries the decay verdict — visible learnings read
|
||||
|
||||
@@ -96,7 +96,8 @@ struct LibrarySearchTests {
|
||||
/// while it `isFresh` for the CURRENT key. The controller pins drive
|
||||
/// the real rescan rail (write verbs + the rail's own rescan Task) and
|
||||
/// prove archive, trash, and a same-query body edit each move the
|
||||
/// revision — without that signal a standing snapshot outlives the
|
||||
/// revision, and an unchanged rescan over a quiesced FSEvent burst
|
||||
/// keeps it — without that signal a standing snapshot outlives the
|
||||
/// library it searched (archived rows linger in the results; edited
|
||||
/// bodies never enter or leave them until the query changes).
|
||||
@Suite("library search snapshot invalidation")
|
||||
@@ -192,9 +193,22 @@ struct LibrarySearchSnapshotTests {
|
||||
let (model, home) = try makeModelHome()
|
||||
let post = try PostStore.writeNew(body: "# Settled\n", home: home)
|
||||
try await pollUntil { model.posts.contains { $0.id == post.id } }
|
||||
// The FSEvent burst can still hold a sibling rescan that snapshotted
|
||||
// its miss count BEFORE the landing scan stamped the shared
|
||||
// PostScanCache — both count the same first read, each bumps the
|
||||
// revision (#144's counter; an extra bump only over-invalidates a
|
||||
// search snapshot). This pin is the SETTLED contract: wait out the
|
||||
// burst (FSEvents latency is 0.5 s) before snapshotting.
|
||||
var quiet = false
|
||||
for _ in 0 ..< 20 where !quiet {
|
||||
let seen = model.contentRevision
|
||||
try await Task.sleep(nanoseconds: 500_000_000)
|
||||
quiet = model.contentRevision == seen
|
||||
}
|
||||
#expect(quiet) // endless revision churn would never settle
|
||||
let settled = model.contentRevision
|
||||
|
||||
await model.rescan() // nothing changed since the last scan — all cache hits
|
||||
await model.rescan() // nothing changed since the burst — all cache hits
|
||||
|
||||
#expect(model.contentRevision == settled)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ struct PolishSeamTests {
|
||||
/// whitespace-only buffer has none (nil); a buffer with no leading
|
||||
/// blanks returns 0. The same walker styles the title line and hops
|
||||
/// programmatic carets past the invisible blank fragment.
|
||||
@Test func `firstContentLocation skips leading blanks`() {
|
||||
@Test func firstContentLocationSkipsLeadingBlanks() {
|
||||
let plain = "Title\n\nbody" as NSString
|
||||
#expect(ProsePresenter.firstContentLocation(plain) == 0)
|
||||
let blankLead = "\n\n \nTitle\nbody" as NSString
|
||||
@@ -31,7 +31,7 @@ struct PolishSeamTests {
|
||||
/// The ladder keeps the full path, then each shorter variant with one
|
||||
/// more leading component kept whole; ≤2 components has nothing to
|
||||
/// elide. `elide` picks the longest candidate that fits.
|
||||
@Test func `ElidedPathText candidate ladder and elision`() {
|
||||
@Test func elidedPathTextCandidateLadderAndElision() {
|
||||
let path = "/Users/alex/Library/Mobile Documents/com~apple~CloudDocs/Museion"
|
||||
let ladder = ElidedPathText.candidates(path)
|
||||
#expect(ladder.first == path)
|
||||
|
||||
@@ -532,7 +532,8 @@ func readPiece(_ home: URL, root: String, project: String, _ id: String) throws
|
||||
withIntermediateDirectories: true,
|
||||
)
|
||||
}
|
||||
#expect(!decomposed.utf8.elementsEqual("한국".utf8)) // two byte sequences, one name — Swift ==/Set already fold; the explicit key pins the contract
|
||||
// two byte sequences, one name — Swift ==/Set already fold; the explicit key pins the contract
|
||||
#expect(!decomposed.utf8.elementsEqual("한국".utf8))
|
||||
#expect(PostStore.availableSlug(for: "한국", home: home) == "한국-2")
|
||||
}
|
||||
|
||||
|
||||
@@ -44,14 +44,17 @@ struct ProfileProvisionerFailureTests {
|
||||
func configUntouched() -> Bool {
|
||||
(try? String(contentsOfFile: configPath, encoding: .utf8)) == config
|
||||
}
|
||||
// Shared per-phase runner: same binary/root/payload master, the
|
||||
// server seam varying per phase (default = perform's own default).
|
||||
func pass(_ payload: String, server: String? = Bundle.main.executableURL?.path) -> ProfileProvisioner.Outcome {
|
||||
ProfileProvisioner.perform(
|
||||
hermesBinary: binary, profileRoot: profileRoot, payloadRoot: payload,
|
||||
masterRoot: master, serverBinaryPath: server,
|
||||
)
|
||||
}
|
||||
|
||||
// Failed pass: registration never reached, config untouched.
|
||||
let failed = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: badPayload,
|
||||
masterRoot: master,
|
||||
)
|
||||
let failed = pass(badPayload)
|
||||
guard case .failed = failed else {
|
||||
Issue.record("expected copy failure, got \(failed)")
|
||||
return
|
||||
@@ -61,13 +64,7 @@ struct ProfileProvisionerFailureTests {
|
||||
// Skipped pass: nil serverBinaryPath is the test seam — nothing
|
||||
// registers, config untouched. (The failed pass already seeded the
|
||||
// shared master — 2 present there, only the 6 profile links copy.)
|
||||
let skipped = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: goodPayload,
|
||||
masterRoot: master,
|
||||
serverBinaryPath: nil,
|
||||
)
|
||||
let skipped = pass(goodPayload, server: nil)
|
||||
#expect(skipped == .seeded(copied: 6, present: 2))
|
||||
#expect(configUntouched())
|
||||
for profile in ["museion", "museion-pass1", "museion-pass2"] {
|
||||
@@ -77,13 +74,7 @@ struct ProfileProvisionerFailureTests {
|
||||
// Registering pass: the CLI rail ran (markers + invocations per
|
||||
// profile) and still not one byte of config.yaml is written by the
|
||||
// provisioner — the entry lands through the CLI, or not at all.
|
||||
let registered = ProfileProvisioner.perform(
|
||||
hermesBinary: binary,
|
||||
profileRoot: profileRoot,
|
||||
payloadRoot: goodPayload,
|
||||
masterRoot: master,
|
||||
serverBinaryPath: "/fake/Museion.app/Contents/MacOS/Museion",
|
||||
)
|
||||
let registered = pass(goodPayload, server: "/fake/Museion.app/Contents/MacOS/Museion")
|
||||
#expect(registered == .seeded(copied: 0, present: 8))
|
||||
#expect(configUntouched())
|
||||
#expect(FileManager.default.fileExists(atPath: (binDir as NSString).appendingPathComponent("mcp-registered-museion")))
|
||||
|
||||
@@ -44,8 +44,8 @@ struct SeedSkill {
|
||||
/// and `config unset <key>` (argv log `<binaryDir>/config-unset-<profile>`,
|
||||
/// store line removed, "✓ Unset …"; unset-when-absent = the not-set line,
|
||||
/// exit 1) — the live-probed wire shapes HermesSettingsWriter pins.
|
||||
// #136: the config rail (set/get/unset over the config-store map) — its
|
||||
// own literal so makeFakeHermes stays under its function-body ceiling.
|
||||
/// #136: the config rail (set/get/unset over the config-store map) — its
|
||||
/// own literal so makeFakeHermes stays under its function-body ceiling.
|
||||
private func fakeHermesConfigCLI() -> String {
|
||||
"""
|
||||
if [[ "$1" == "-p" && "$3" == "config" && "$4" == "set" ]]; then
|
||||
@@ -94,6 +94,67 @@ private func fakeHermesConfigCLI() -> String {
|
||||
"""
|
||||
}
|
||||
|
||||
/// #23: the mcp rail (list/add over marker files) — its own literal so
|
||||
/// makeFakeHermes stays under its function-body ceiling (config-rail
|
||||
/// precedent directly above).
|
||||
private func fakeHermesMcpCLI() -> String {
|
||||
"""
|
||||
if [[ "$1" == "-p" && "$3" == "mcp" ]]; then
|
||||
PROFILE="$2"
|
||||
if [[ "$4" == "list" ]]; then
|
||||
if [[ -f "${0:h}/mcp-registered-$PROFILE" ]]; then
|
||||
print "museion-tools enabled"
|
||||
exit 0
|
||||
fi
|
||||
print "No MCP servers configured."
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$4" == "add" ]]; then
|
||||
if [[ "$5" != "museion-tools" || "$6" != "--command" || -z "$7" || "$8" != "--args" || "$9" != "--serve-mcp" ]]; then
|
||||
print "Error: mcp add unexpected argv: $5 $6 $7 $8 $9"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -f "${0:h}/mcp-add-fails" ]]; then
|
||||
print "Error: mcp add exploded"
|
||||
exit 1
|
||||
fi
|
||||
read -r ANSWER
|
||||
if [[ "$ANSWER" != "y" ]]; then
|
||||
print "Cancelled."
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
"""
|
||||
}
|
||||
|
||||
/// Fake `hermes`: `profile create <name>` behaves per `mode` (#43 semantics).
|
||||
/// - ok: creates the dir, exit 0. exists: creates the dir, "already exists" on
|
||||
/// 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` 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` / `config-unset-fails`
|
||||
/// force the matching failure. Every `profile create` name appends to
|
||||
/// `<binaryDir>/profile-create-log`.
|
||||
/// #136: `config set` also records KEY=VALUE into
|
||||
/// `<binaryDir>/config-store-<profile>` (dedup per key), and the fake speaks
|
||||
/// `config get <key>` (store value, or the not-set line on stderr exit 1)
|
||||
/// and `config unset <key>` (argv log `<binaryDir>/config-unset-<profile>`,
|
||||
/// store line removed, "✓ Unset …"; unset-when-absent = the not-set line,
|
||||
/// exit 1) — the live-probed wire shapes HermesSettingsWriter pins.
|
||||
func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> String {
|
||||
let path = (dir as NSString).appendingPathComponent(name)
|
||||
let createBlock = switch mode {
|
||||
@@ -128,36 +189,7 @@ func makeFakeHermes(at dir: String, name: String = "hermes", mode: String) -> St
|
||||
print -r -- "$NAME" >> "${0:h}/profile-create-log"
|
||||
\(createBlock)
|
||||
fi
|
||||
if [[ "$1" == "-p" && "$3" == "mcp" ]]; then
|
||||
PROFILE="$2"
|
||||
if [[ "$4" == "list" ]]; then
|
||||
if [[ -f "${0:h}/mcp-registered-$PROFILE" ]]; then
|
||||
print "museion-tools enabled"
|
||||
exit 0
|
||||
fi
|
||||
print "No MCP servers configured."
|
||||
exit 0
|
||||
fi
|
||||
if [[ "$4" == "add" ]]; then
|
||||
if [[ "$5" != "museion-tools" || "$6" != "--command" || -z "$7" || "$8" != "--args" || "$9" != "--serve-mcp" ]]; then
|
||||
print "Error: mcp add unexpected argv: $5 $6 $7 $8 $9"
|
||||
exit 1
|
||||
fi
|
||||
if [[ -f "${0:h}/mcp-add-fails" ]]; then
|
||||
print "Error: mcp add exploded"
|
||||
exit 1
|
||||
fi
|
||||
read -r ANSWER
|
||||
if [[ "$ANSWER" != "y" ]]; then
|
||||
print "Cancelled."
|
||||
exit 1
|
||||
fi
|
||||
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
|
||||
\(fakeHermesMcpCLI())
|
||||
\(fakeHermesConfigCLI())
|
||||
exit 97
|
||||
"""
|
||||
|
||||
@@ -343,7 +343,8 @@ struct ProfileSurfaceTests {
|
||||
)
|
||||
#expect(outcome == .seeded(copied: 8, present: 0))
|
||||
for profile in ProfileSurface.allCases {
|
||||
#expect(!FileManager.default.fileExists(atPath: (binDir as NSString).appendingPathComponent("mcp-add-invocation-\(profile.profileName)")))
|
||||
let invocation = (binDir as NSString).appendingPathComponent("mcp-add-invocation-\(profile.profileName)")
|
||||
#expect(!FileManager.default.fileExists(atPath: invocation))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,11 @@ struct ProsePresenterTests {
|
||||
// sample at the heading TEXT, not offset 0 (the dimmed marker)
|
||||
let h1 = attributed.attribute(.font, at: ns.range(of: "H1").location, effectiveRange: nil) as? NSFont
|
||||
#expect(h1?.pointSize == 30)
|
||||
#expect(h1?.fontName.contains("ConcourseOT") == true || h1?.fontName.contains("Semibold") == true || h1?.fontName.contains("Bold") == true)
|
||||
#expect(
|
||||
h1?.fontName.contains("ConcourseOT") == true
|
||||
|| h1?.fontName.contains("Semibold") == true
|
||||
|| h1?.fontName.contains("Bold") == true,
|
||||
)
|
||||
let h2 = attributed.attribute(.font, at: ns.range(of: "H2").location, effectiveRange: nil) as? NSFont
|
||||
#expect(h2?.pointSize == 22)
|
||||
let h3 = attributed.attribute(.font, at: ns.range(of: "H3").location, effectiveRange: nil) as? NSFont
|
||||
|
||||
@@ -27,7 +27,8 @@ struct ReadingPresenterTests {
|
||||
@Test
|
||||
func `stamper rewrites attributes`() {
|
||||
let html = "<h1>T</h1>\n<!--S:1-->\n<p>A</p>\n<!--S:12-->\n<ul>\n<li>B</li>\n</ul>"
|
||||
#expect(ReadingPresenter.stampHTML(html) == "<h1>T</h1>\n<p data-source-line=\"1\">A</p>\n<ul data-source-line=\"12\">\n<li>B</li>\n</ul>")
|
||||
let expected = "<h1>T</h1>\n<p data-source-line=\"1\">A</p>\n<ul data-source-line=\"12\">\n<li>B</li>\n</ul>"
|
||||
#expect(ReadingPresenter.stampHTML(html) == expected)
|
||||
}
|
||||
|
||||
/// The #68 click→edit map: blocks are monotonic, lines are 1-based, and
|
||||
|
||||
Reference in new issue
Block a user