feat(sessions): keep every session, record review details, name and stamp the PDF

Sessions are now the unit of the product instead of an implicit capture run.

- Nothing is deleted by default: the fixed 10-session cap is gone. An age limit
  (Never / 7 / 14 / 30 / 90 / 180 / 365 days) is chosen in Settings > Sessions and
  applied on launch, after archiving, and by "Clean up now". Sent PDFs are never
  touched.
- Each session carries review details: lane, deployed version, commit, reviewer
  (pre-filled with the Mac user) and a free note. They persist in session.json and
  are inherited by the next session, so a review run is typed once.
- PDF file names are Redline-<yyyyMMdd-HHmm>-<LANE>-<SHORTID>.pdf, and every page
  carries a two-line reference footer (tool, build time, session / lane, deployed
  build, commit, reviewer, note). The PDF document info carries the same values in
  Author and Keywords.
- Verification: 159 tests, a headless panel self-test, and a LaunchServices-driven
  end-to-end run that types and clicks the real panel.
This commit is contained in:
Claude Fable 5
2026-10-31 11:32:54 +04:00
parent 542aad296b
commit 02fa791b78
26 changed files with 2780 additions and 279 deletions
+110 -4
View File
@@ -203,17 +203,123 @@ private func pixelWindow(
return (pixelX0, pixelY0, pixelX1, pixelY1)
}
@Test("fileName uses compose time, not session.createdAt, and matches Redline-yyyyMMdd-HHmmss.pdf")
@Test("fileName is Redline-yyyyMMdd-HHmm-SHORTID.pdf and uses compose time")
func fileNameUsesComposeTimeNotSessionCreatedAt() {
let old = Date(timeIntervalSince1970: 1_600_000_000) // 2020-09-13
let session = makeSession(captures: [], createdAt: old)
let name = PDFComposer.fileName(for: session)
#expect(name.wholeMatch(of: /^Redline-\d{8}-\d{6}\.pdf$/) != nil)
#expect(!name.contains(DubaiTime.fileStamp(old)))
let today = String(DubaiTime.fileStamp(Date()).prefix(8))
#expect(name.wholeMatch(of: /^Redline-\d{8}-\d{4}-[0-9A-F]{8}\.pdf$/) != nil)
#expect(name.contains(session.shortID))
#expect(!name.contains(DubaiTime.fileMinuteStamp(old)))
let today = String(DubaiTime.fileMinuteStamp(Date()).prefix(8))
#expect(name.contains(today))
}
@Test("fileName carries the lane slug between the timestamp and the session id")
func fileNameCarriesTheLaneSlug() {
let session = CaptureSession(
id: UUID(uuidString: "4f2a9c1d-0000-4000-8000-000000000000")!,
createdAt: fixtureDate,
state: .open,
captures: [],
pdfFileName: nil,
context: ReviewContext(lane: "OMS test lane"))
let name = PDFComposer.fileName(for: session)
#expect(name.wholeMatch(of: /^Redline-\d{8}-\d{4}-OMS-TEST-LANE-4F2A9C1D\.pdf$/) != nil)
}
@Test("Review footer lines state the tool, date, session and the recorded review details")
func footerLinesStateTheReviewDetails() {
let session = CaptureSession(
id: UUID(uuidString: "4f2a9c1d-0000-4000-8000-000000000000")!,
createdAt: fixtureDate,
state: .open,
captures: [],
pdfFileName: nil,
context: ReviewContext(
lane: "dev03", deployedVersion: "v1.4.2 (41)", commit: "a1b2c3d4",
reviewer: "Ben Hippler", note: "checkout"))
let lines = PDFComposer.footerLines(
session: session, toolVersion: "0.5.0", composedAt: fixtureDate)
#expect(lines.count == 2)
#expect(lines[0].contains("Redline 0.5.0"))
#expect(lines[0].contains("Session 4F2A9C1D"))
#expect(lines[0].contains(DubaiTime.stamp(fixtureDate)))
#expect(lines[1].contains("Lane dev03"))
#expect(lines[1].contains("Deployed v1.4.2 (41)"))
#expect(lines[1].contains("Commit a1b2c3d4"))
#expect(lines[1].contains("Reviewer Ben Hippler"))
#expect(lines[1].contains("Note checkout"))
// A session with no recorded details still identifies itself; nothing is faked.
let bare = makeSession(captures: [])
let bareLines = PDFComposer.footerLines(
session: bare, toolVersion: "", composedAt: fixtureDate)
#expect(bareLines.count == 1)
#expect(bareLines[0].hasPrefix("Redline · "))
}
@Test("Document info carries the reviewer and the lane/build/commit keywords")
func documentInfoCarriesTheReviewDetails() {
let session = CaptureSession(
id: UUID(uuidString: "deadbeef-dead-4eef-8ead-deadbeef0001")!,
createdAt: fixtureDate,
state: .open,
captures: [],
pdfFileName: nil,
context: ReviewContext(
lane: "DEV03", deployedVersion: "v1.4.2", commit: "a1b2c3d4",
reviewer: "Ben Hippler", note: "checkout"))
let info = PDFComposer.documentInfo(
session: session, title: "Redline – DEV03", toolVersion: "0.5.0", composedAt: fixtureDate)
#expect(info[kCGPDFContextAuthor as String] as? String == "Ben Hippler")
#expect(info[kCGPDFContextCreator as String] as? String == "Redline 0.5.0")
let keywords = try? #require(info[kCGPDFContextKeywords as String] as? String)
#expect(keywords?.contains("lane=DEV03") == true)
#expect(keywords?.contains("deployed=v1.4.2") == true)
#expect(keywords?.contains("commit=a1b2c3d4") == true)
#expect(keywords?.contains("reviewer=Ben Hippler") == true)
#expect(keywords?.contains("built=\(DubaiTime.keywordStamp(fixtureDate))") == true)
}
@Test("A composed PDF carries the footer text and document info a reader can see")
func composedPDFCarriesTheReferenceBlock() throws {
let directory = try makeScratchDirectory()
defer { try? FileManager.default.removeItem(at: directory) }
let capture = makeCapture(sequence: 1, pixelWidth: 800, pixelHeight: 600)
let png = try writePNG(for: capture, red: 60, green: 60, blue: 60, in: directory)
let session = CaptureSession(
id: UUID(uuidString: "4f2a9c1d-0000-4000-8000-000000000000")!,
createdAt: fixtureDate,
state: .open,
captures: [capture],
pdfFileName: nil,
context: ReviewContext(
lane: "dev03", deployedVersion: "v1.4.2", commit: "a1b2c3d4",
reviewer: "Ben Hippler", note: "checkout"))
let output = directory.appendingPathComponent("footer.pdf")
_ = try PDFComposer().compose(
session: session,
imageURL: { _ in png },
title: "Redline – dev03",
to: output,
toolVersion: "0.5.0",
composedAt: fixtureDate
)
let document = try openDocument(output)
let pageText = try #require(document.page(at: 0)?.string ?? "")
#expect(pageText.contains("Redline 0.5.0"))
#expect(pageText.contains("Lane dev03"))
#expect(pageText.contains("Commit a1b2c3d4"))
#expect(pageText.contains("Ben Hippler"))
let attributes = try #require(document.documentAttributes)
#expect(attributes[PDFDocumentAttribute.authorAttribute] as? String == "Ben Hippler")
}
@Test("Three-page basic compose")
func threePageBasicCompose() throws {
let directory = try makeScratchDirectory()