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:
@@ -6,15 +6,15 @@ import Testing
|
||||
import ShotdeckCore
|
||||
@testable import Shotdeck
|
||||
|
||||
/// MMDB-2925, through the REAL app-target seams the menu rows invoke (`AppModel`
|
||||
/// actions + `SpoolStore`): "Start new session" keeps the current screenshots as a
|
||||
/// past session, the Past submissions state reflects what was sent, and session
|
||||
/// retention keeps the newest 10 sessions in the one archive folder. `bootstrap()`
|
||||
/// itself is covered by LaunchWiringTests; here `addCapture` refreshes the session
|
||||
/// from the store exactly the way `AppModel.captureNow()` does after a real capture.
|
||||
/// Through the REAL app-target seams the menu rows invoke (`AppModel` actions +
|
||||
/// `SpoolStore`): "Start new session" keeps the current screenshots as a past session,
|
||||
/// the Past sessions state reflects what was sent, every session is kept by default,
|
||||
/// and a chosen age limit is what removes one. `bootstrap()` itself is covered by
|
||||
/// LaunchWiringTests; here `addCapture` refreshes the session from the store exactly
|
||||
/// the way `AppModel.captureNow()` does after a real capture.
|
||||
@MainActor
|
||||
@Test("Menu actions: start new session keeps captures, lists past submissions, retains 10")
|
||||
func startNewSessionKeepsCapturesListsPastSubmissionsAndRetainsTen() async throws {
|
||||
@Test("Menu actions: start new session keeps captures and lists past submissions")
|
||||
func startNewSessionKeepsCapturesAndListsPastSessions() async throws {
|
||||
let fm = FileManager.default
|
||||
let root = fm.temporaryDirectory
|
||||
.appendingPathComponent("shotdeck-session-workflow-\(UUID().uuidString)", isDirectory: true)
|
||||
@@ -51,8 +51,8 @@ func startNewSessionKeepsCapturesListsPastSubmissionsAndRetainsTen() async throw
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test("Retention: 12 sessions through the menu action leave the newest 10 on disk")
|
||||
func twelveSessionsLeaveTheNewestTenInTheOneArchiveFolder() async throws {
|
||||
@Test("Retention: 12 sessions through the menu action are all kept by default")
|
||||
func twelveSessionsStayOnDiskByDefault() async throws {
|
||||
let fm = FileManager.default
|
||||
let root = fm.temporaryDirectory
|
||||
.appendingPathComponent("shotdeck-session-workflow-\(UUID().uuidString)", isDirectory: true)
|
||||
@@ -66,16 +66,91 @@ func twelveSessionsLeaveTheNewestTenInTheOneArchiveFolder() async throws {
|
||||
await model.startNewSession()
|
||||
}
|
||||
|
||||
#expect(model.pastSessions.count == SpoolStore.defaultRetainedSessionCount)
|
||||
#expect(model.pastSessions.map(\.id)
|
||||
== Array(closedIDs.suffix(SpoolStore.defaultRetainedSessionCount).reversed()))
|
||||
#expect(model.retention == .never)
|
||||
#expect(model.pastSessions.map(\.id) == closedIDs.reversed())
|
||||
|
||||
let entries = try fm.contentsOfDirectory(at: model.paths.archive, includingPropertiesForKeys: nil)
|
||||
let sessionDirs = entries.filter { UUID(uuidString: $0.lastPathComponent) != nil }
|
||||
#expect(sessionDirs.count == SpoolStore.defaultRetainedSessionCount)
|
||||
for id in closedIDs.prefix(2) {
|
||||
#expect(!fm.fileExists(atPath: model.paths.archiveDirectory(id).path))
|
||||
#expect(sessionDirs.count == closedIDs.count)
|
||||
for id in closedIDs {
|
||||
#expect(fm.fileExists(atPath: model.paths.archiveDirectory(id).path))
|
||||
}
|
||||
#expect(model.expiredSessionCount == 0)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test("A review detail typed in the panel is saved and inherited by the next session")
|
||||
func reviewDetailsPersistThroughTheModel() async throws {
|
||||
let fm = FileManager.default
|
||||
let root = fm.temporaryDirectory
|
||||
.appendingPathComponent("shotdeck-session-workflow-\(UUID().uuidString)", isDirectory: true)
|
||||
defer { try? fm.removeItem(at: root) }
|
||||
let model = AppDelegate.makeLaunchModel(appSupportRoot: root)
|
||||
|
||||
let context = ReviewContext(
|
||||
lane: "dev03", deployedVersion: "v1.4.2", commit: "a1b2c3d4",
|
||||
reviewer: "Ben Hippler", note: "checkout")
|
||||
await model.setContextField(context)
|
||||
#expect(model.session.context == context)
|
||||
#expect(model.sessionContext.summaryLine == "dev03 · v1.4.2 · a1b2c3d4 · Ben Hippler")
|
||||
#expect(model.nextPDFFileNameHint.contains("-DEV03-"))
|
||||
|
||||
_ = try await addCapture(to: model, red: 0.1, green: 0.4, blue: 0.9)
|
||||
await model.startNewSession()
|
||||
|
||||
// The closed session keeps its details; the new one inherits them.
|
||||
#expect(model.pastSessions.first?.context == context)
|
||||
#expect(model.session.context == context)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@Test("Settings age limit: cleanup removes only expired sessions, never a sent PDF")
|
||||
func cleanUpHonorsTheAgeLimit() async throws {
|
||||
let fm = FileManager.default
|
||||
let root = fm.temporaryDirectory
|
||||
.appendingPathComponent("shotdeck-session-workflow-\(UUID().uuidString)", isDirectory: true)
|
||||
defer { try? fm.removeItem(at: root) }
|
||||
let suite = try makeIsolatedDefaults()
|
||||
defer { suite.defaults.removePersistentDomain(forName: suite.name) }
|
||||
let model = AppDelegate.makeLaunchModel(
|
||||
appSupportRoot: root, retentionDefaults: suite.defaults)
|
||||
await model.bootstrap()
|
||||
|
||||
// One real session that was sent (its PDF is in the outbox) …
|
||||
_ = try await addCapture(to: model, red: 0.6, green: 0.2, blue: 0.2)
|
||||
let sentName = "Redline-20261001-0900-A1B2C3D4.pdf"
|
||||
_ = try await model.spool.archiveCurrent(pdfFileName: sentName)
|
||||
try Data("%PDF-1.4\n% test\n".utf8)
|
||||
.write(to: model.paths.outbox.appendingPathComponent(sentName))
|
||||
|
||||
// … and one archived session backdated past the limit, written in the exact shape
|
||||
// production writes, so the age comparison runs against real manifest dates.
|
||||
let expiredID = try await writeBackdatedSession(in: model.paths, daysAgo: 40)
|
||||
await model.reloadFromSpool()
|
||||
|
||||
#expect(model.pastSessions.count == 2)
|
||||
|
||||
// Nothing expires under .never, even with a cleanup.
|
||||
await model.cleanUpExpiredSessions()
|
||||
#expect(model.pastSessions.count == 2)
|
||||
#expect(model.expiredSessionCount == 0)
|
||||
#expect(model.statusLine?.contains("Nothing to remove") == true)
|
||||
|
||||
// A 30-day limit expires only the backdated session, and says so before deleting.
|
||||
await model.setRetention(.days(30))
|
||||
#expect(model.retention == .days(30))
|
||||
#expect(RetentionSettings.load(defaults: suite.defaults) == .days(30))
|
||||
#expect(model.expiredSessionCount == 1)
|
||||
|
||||
await model.cleanUpExpiredSessions()
|
||||
#expect(model.pastSessions.count == 1)
|
||||
#expect(model.statusLine?.contains("Removed 1 past session") == true)
|
||||
#expect(!fm.fileExists(atPath: model.paths.archiveDirectory(expiredID).path))
|
||||
#expect(fm.fileExists(atPath: model.paths.outbox.appendingPathComponent(sentName).path))
|
||||
|
||||
// Back to the default in this isolated suite, so the next test starts clean.
|
||||
await model.setRetention(.never)
|
||||
#expect(model.expiredSessionCount == 0)
|
||||
}
|
||||
|
||||
@MainActor
|
||||
@@ -191,6 +266,49 @@ private enum FixtureError: Error {
|
||||
case pngGenerationFailed
|
||||
}
|
||||
|
||||
// MARK: - Fixtures
|
||||
|
||||
private struct IsolatedDefaults {
|
||||
let name: String
|
||||
let defaults: UserDefaults
|
||||
}
|
||||
|
||||
/// A throwaway UserDefaults suite — never `.standard` — so the age-limit setting a
|
||||
/// test writes can never change Ben's real app preference.
|
||||
private func makeIsolatedDefaults() throws -> IsolatedDefaults {
|
||||
let name = "shotdeck-session-workflow-\(UUID().uuidString)"
|
||||
guard let defaults = UserDefaults(suiteName: name) else {
|
||||
throw FixtureError.pngGenerationFailed
|
||||
}
|
||||
defaults.removePersistentDomain(forName: name)
|
||||
return IsolatedDefaults(name: name, defaults: defaults)
|
||||
}
|
||||
|
||||
/// Writes an archived session folder dated `daysAgo` days in the past, in the exact
|
||||
/// on-disk shape the store produces, so an age policy can act on a real manifest date.
|
||||
@discardableResult
|
||||
private func writeBackdatedSession(in paths: AppSupportPaths, daysAgo: Int) async throws -> UUID {
|
||||
let id = UUID()
|
||||
let createdAt = Date().addingTimeInterval(-Double(daysAgo) * 86_400)
|
||||
let dir = paths.archiveDirectory(id)
|
||||
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
|
||||
let pngName = "001-\(String(id.uuidString.prefix(8)).uppercased()).png"
|
||||
try makePNGData(width: 8, height: 8, red: 0.3, green: 0.3, blue: 0.3)
|
||||
.write(to: dir.appendingPathComponent(pngName))
|
||||
let capture = Capture(
|
||||
id: UUID(), sequence: 1, fileName: pngName,
|
||||
pixelWidth: 8, pixelHeight: 8, scale: 1.0, capturedAt: createdAt)
|
||||
let session = CaptureSession(
|
||||
id: id, createdAt: createdAt, state: .archived, captures: [capture],
|
||||
pdfFileName: nil,
|
||||
context: ReviewContext(lane: "DEV03", deployedVersion: "v1.0.0", commit: "abc1234"))
|
||||
let encoder = JSONEncoder()
|
||||
encoder.dateEncodingStrategy = .iso8601
|
||||
try encoder.encode(session).write(to: dir.appendingPathComponent("session.json"))
|
||||
return id
|
||||
}
|
||||
|
||||
|
||||
private func makePNGData(
|
||||
width: Int,
|
||||
height: Int,
|
||||
|
||||
Reference in New Issue
Block a user