Files
shotdeck/Sources/ShotdeckCore/PDF/PDFFileName.swift
Claude Fable 5 02fa791b78 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.
2026-10-31 11:32:54 +04:00

55 lines
2.3 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// The PDF file-name scheme:
///
/// Redline-<yyyyMMdd-HHmm>-<LANE>-<SHORTID>.pdf
/// Redline-<yyyyMMdd-HHmm>-<SHORTID>.pdf (no lane recorded)
///
/// * `yyyyMMdd-HHmm` is Dubai wall-clock time (the time the PDF was built) — the
/// file sorts chronologically as plain text on every filesystem.
/// * `LANE` is the upper-cased lane/environment, reduced to A–Z, 0–9 and single
/// dashes ("OMS test lane" → "OMS-TEST-LANE") so the name is safe everywhere.
/// * `SHORTID` is the session's 8-character id, which keeps two lanes in the same
/// minute — and a re-send of the same session — distinguishable and unique.
public enum PDFFileName {
/// Lane token length cap so the whole name stays comfortably short.
public static let laneMaxLength = 24
public static func laneSlug(_ lane: String) -> String {
var slug = ""
var pendingDash = false
for character in lane.uppercased() {
if character.isASCII, character.isLetter || character.isNumber {
if pendingDash, !slug.isEmpty { slug.append("-") }
slug.append(character)
pendingDash = false
} else {
pendingDash = true
}
}
let capped = String(slug.prefix(laneMaxLength))
return capped.hasSuffix("-") ? String(capped.dropLast()) : capped
}
public static func make(builtAt: Date, lane: String, sessionID: UUID) -> String {
let shortID = String(
sessionID.uuidString.replacingOccurrences(of: "-", with: "").prefix(8)
).uppercased()
let slug = laneSlug(lane)
var parts = ["Redline", DubaiTime.fileMinuteStamp(builtAt)]
if !slug.isEmpty { parts.append(slug) }
parts.append(shortID)
return parts.joined(separator: "-") + ".pdf"
}
/// The session folder's own readable label, e.g. "DEV03-4F2A9C1D" — used in the
/// UI only; the on-disk folder name stays the session UUID.
public static func sessionLabel(lane: String, sessionID: UUID) -> String {
let shortID = String(
sessionID.uuidString.replacingOccurrences(of: "-", with: "").prefix(8)
).uppercased()
let slug = laneSlug(lane)
return slug.isEmpty ? shortID : "\(slug)-\(shortID)"
}
}