The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.
An Auto space follows macOS again with one colour, and shipped-issue tests are locked (#155)
Victor740441a9eb0c
diff --git a/.claude/settings.json b/.claude/settings.jsonindex d6dc80c..40cdbdf 100644--- a/.claude/settings.json+++ b/.claude/settings.json@@ -9,6 +9,12 @@"command": "\"$CLAUDE_PROJECT_DIR\"/scripts/clips/check-release-media.sh","timeout": 30,"statusMessage": "Checking the release notes have clips"+ },+ {+ "type": "command",+ "command": "\"$CLAUDE_PROJECT_DIR\"/scripts/check-promises-hook.sh",+ "timeout": 30,+ "statusMessage": "Checking shipped-issue tests against Tests/promises.lock"}]}diff --git a/CLAUDE.md b/CLAUDE.mdindex fe8ef93..605669e 100644--- a/CLAUDE.md+++ b/CLAUDE.md@@ -36,6 +36,10 @@ through `Sources/Cra/App/CraCoreExports.swift`.record the new expectation and say why in the PR.5. **Run `scripts/test.sh` before a PR.** CI runs it as well, with the coverage gates indocs/testing.md.+6. **A fix for an issue comes with a test tagged `.bug(".../issues/<n>")`**, locked in+ `Tests/promises.lock`. When a locked test fails, the change broke something that shipped: fix+ the change, not the test. Only Victor decides that a shipped behaviour changes; then run+ `scripts/promises.py --update` and name the issue in the commit (docs/testing.md rule 8).## Known exceptionsdiff --git a/Packages/CraCore/Sources/CraCore/SpaceTheme.swift b/Packages/CraCore/Sources/CraCore/SpaceTheme.swiftindex cf91541..48010fa 100644--- a/Packages/CraCore/Sources/CraCore/SpaceTheme.swift+++ b/Packages/CraCore/Sources/CraCore/SpaceTheme.swift@@ -19,8 +19,9 @@ public struct SpaceTheme: Codable, Equatable {public var solid: Bool = false/// Arc's Auto theme (background.appearanceBased): with `appearance` "auto" the space follows/// macOS, the fields above are its light half and this is the half shown while macOS is dark.- /// nil on an "auto" theme with one set of colours (saved before 0.1.29, the Edit Space sheet's- /// Auto, a Zen import): it stays on the side its colours suit whatever macOS shows.+ /// nil on an "auto" theme with one set of colours (saved before 0.1.29, the old Edit Space sheet's+ /// Auto, a Zen import): it stays on the side its colours suit whatever macOS shows. The theme+ /// editor's Auto always writes both halves (SpaceThemeVariants).public var dark: Variant? = nil/// The theme editor's pad colours the theme was built from (Arc: the editor's key colour and/// the ones its wheel adds); nil for a preset or an import, whose own colours go on the pad.@@ -35,6 +36,18 @@ public struct SpaceTheme: Codable, Equatable {public var accent: String? = nilpublic var solid: Bool = false+ /// A half written without `vibrant` or `solid` (by hand, or by a later Cra that drops them)+ /// reads them as off instead of failing the file.+ public init(from decoder: Decoder) throws {+ let c = try decoder.container(keyedBy: CodingKeys.self)+ colors = try c.decode([String].self, forKey: .colors)+ intensity = try c.decode(Double.self, forKey: .intensity)+ noise = try c.decodeIfPresent(Double.self, forKey: .noise) ?? 0+ vibrant = try c.decodeIfPresent(Bool.self, forKey: .vibrant) ?? false+ accent = try c.decodeIfPresent(String.self, forKey: .accent)+ solid = try c.decodeIfPresent(Bool.self, forKey: .solid) ?? false+ }+public init(colors: [String], intensity: Double, noise: Double, vibrant: Bool = false, accent: String? = nil, solid: Bool = false) {self.colors = colorsself.intensity = intensity@@ -74,7 +87,8 @@ public struct SpaceTheme: Codable, Equatable {vibrant = try c.decodeIfPresent(Bool.self, forKey: .vibrant) ?? falseaccent = try c.decodeIfPresent(String.self, forKey: .accent)solid = try c.decodeIfPresent(Bool.self, forKey: .solid) ?? false- dark = try c.decodeIfPresent(Variant.self, forKey: .dark)+ // A dark half that can't be read is dropped, not the whole sidebar.json with it.+ dark = (try? c.decodeIfPresent(Variant.self, forKey: .dark)) ?? nilkey = try c.decodeIfPresent([String].self, forKey: .key)}diff --git a/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift b/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swiftindex 6283fab..bed701a 100644--- a/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift+++ b/Packages/CraCore/Sources/CraCore/SpaceThemeVariants.swift@@ -4,14 +4,12 @@ import Foundation/// `background.appearanceBased` from the editor's key colour).public enum SpaceThemeVariants {/// What the theme editor makes of its pad: both halves for Auto, one for Light or Dark.+ /// Auto always gets both halves, one colour too (#155): Arc saves a swatch picked on Auto as one+ /// `single` theme that never changes with macOS, and copying that (0.1.30–0.1.32) left a space set+ /// to Auto stuck on one side. An imported Arc `single` stays on its side (ArcThemeImport, #171).public static func theme(key: [String], intensity: Double, noise: Double, appearance: String) -> SpaceTheme {var t: SpaceThemeswitch appearance {- // One colour on Auto: Arc saves a picked swatch as one `single` theme in that colour, on the- // side the colour suits (an imported one reads the same way, ArcThemeImport).- case "auto" where key.count == 1:- t = SpaceTheme(colors: [key[0], key[0]], intensity: intensity, noise: noise, appearance: "auto", accent: key[0], solid: true)- t.appearance = t.isDark ? "dark" : "light"case "light": t = light(key: key, intensity: intensity, noise: noise)case "dark": t = dark(key: key, intensity: intensity, noise: noise)default: t = SpaceTheme(light: light(key: key, intensity: intensity, noise: noise), dark: dark(key: key, intensity: intensity, noise: noise))diff --git a/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift b/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swiftindex 735dab7..81a61c3 100644--- a/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift@@ -184,7 +184,8 @@ struct SpaceThemeAppearanceTests {static let light = SpaceTheme(colors: ["#CDCDFC", "#FFE5E5"], intensity: 0.5, noise: 0, appearance: "light", accent: "#C8CAFF")static let dark = SpaceTheme(colors: ["#2C273B", "#32263A"], intensity: 1, noise: 0, appearance: "dark", accent: "#010220")- @Test func autoShowsTheHalfMacOSAsksFor() {+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/155"))+ func autoShowsTheHalfMacOSAsksFor() {let theme = SpaceTheme(light: Self.light, dark: Self.dark)#expect(theme.followsSystem)#expect(theme.resolved(systemDark: false) == Self.light)@@ -199,7 +200,7 @@ struct SpaceThemeAppearanceTests {/// An Auto theme with one set of colours (saved before 0.1.29, or an import that had no second/// half) stays on the side its colours suit while macOS changes: no derived half (#171).- @Test(arguments: ["#F8D558", "#2861B3", "#F25E6B"])+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/171"), arguments: ["#F8D558", "#2861B3", "#F25E6B"])func autoThemeWithOneHalfKeepsItsLook(hex: String) {let theme = SpaceTheme(colors: [hex, hex], intensity: 0.8, noise: 0.1, appearance: "auto")var own = theme@@ -208,6 +209,48 @@ struct SpaceThemeAppearanceTests {#expect(theme.resolved(systemDark: true) == own)}+ /// Every swatch the editor offers, with one, two or three colours on the pad, picked on Auto+ /// follows macOS: a light half while macOS is light, a dark half while it is dark, both kept+ /// through a save, and the editor reopens on Auto. 0.1.30–0.1.32 saved one colour on Auto (the+ /// editor's default) as a fixed light or dark theme, and the space stopped following macOS (#155).+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/155"), arguments: SpaceColorPresets.pages.flatMap(\.swatches), 1...3)+ func everySwatchOnAutoFollowsMacOS(swatch: [String], colours: Int) throws {+ // The pad's + adds colours round the wheel from the first (SpaceColorWheel).+ let first = SpaceColorWheel.hsb(swatch[0])+ let key = (0..<colours).map { i in+ swatch.indices.contains(i) ? swatch[i]+ : SpaceColorWheel.hex(hue: (first.hue + SpaceColorWheel.offset(i) + 360).truncatingRemainder(dividingBy: 360),+ saturation: first.saturation, brightness: first.brightness)+ }+ let theme = SpaceThemeVariants.theme(key: key, intensity: 0.5, noise: 0.2, appearance: "auto")+ // The editor reads its Auto / Light / Dark back from `appearance` (SpaceStyleEditor).+ #expect(theme.appearance == "auto" && theme.followsSystem && theme.key == key)+ let saved = try JSONDecoder().decode(SpaceTheme.self, from: JSONEncoder().encode(theme))+ #expect(saved == theme)+ let light = saved.resolved(systemDark: false), dark = saved.resolved(systemDark: true)+ #expect(!light.isDark && dark.isDark && light.colors != dark.colors)+ }++ /// Light and Dark keep one look whatever macOS shows, for every swatch (#155).+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/155"), arguments: SpaceColorPresets.pages.flatMap(\.swatches), ["light", "dark"])+ func everySwatchOnLightOrDarkKeepsOneLook(swatch: [String], appearance: String) {+ let theme = SpaceThemeVariants.theme(key: swatch, intensity: 0.5, noise: 0.2, appearance: appearance)+ #expect(!theme.followsSystem && theme.dark == nil && theme.appearance == appearance)+ #expect(theme.resolved(systemDark: false) == theme.resolved(systemDark: true))+ #expect(theme.isDark == (appearance == "dark"))+ }++ /// A dark half written without its optional fields loads with them off, and one that can't be+ /// read at all is dropped: before, either set the whole sidebar.json aside as corrupt.+ @Test func unreadableDarkHalfDropsOnlyTheHalf() throws {+ let partial = ##"{"colors":["#AA0000","#AA0000"],"intensity":1,"noise":0,"appearance":"auto","dark":{"colors":["#110000","#110000"],"intensity":1}}"##+ let theme = try JSONDecoder().decode(SpaceTheme.self, from: Data(partial.utf8))+ #expect(theme.dark == SpaceTheme.Variant(colors: ["#110000", "#110000"], intensity: 1, noise: 0))+ let broken = ##"{"colors":["#AA0000","#AA0000"],"intensity":1,"noise":0,"appearance":"auto","dark":{"colors":5}}"##+ let kept = try JSONDecoder().decode(SpaceTheme.self, from: Data(broken.utf8))+ #expect(kept.dark == nil && kept.colors == ["#AA0000", "#AA0000"])+ }+/// Both halves and the editor's colours are saved; a theme without them saves as before.@Test func roundTripsBothHalves() throws {var theme = SpaceTheme(light: Self.light, dark: Self.dark)@@ -230,9 +273,12 @@ struct SpaceThemeAppearanceTests {let light = theme.resolved(systemDark: false), dark = theme.resolved(systemDark: true)#expect(light.colors == ["#8389FF", "#FF83C8"] && !light.isDark)#expect(close(dark.accent, "#01021F") && dark.isDark)- // One colour on Auto is Arc's one-dot `single` theme: that colour, flat, on the side it suits (#170).+ // One colour on Auto is a flat fill on both halves: the colour while macOS is light, its hue+ // dark while macOS is dark (#155; not Arc's fixed `single`, see everySwatchOnAutoFollowsMacOS).let one = SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "auto")- #expect(one.colors == ["#8389FF", "#8389FF"] && one.solid && one.appearance == "light" && one.key == ["#8389FF"])+ #expect(one.followsSystem && one.key == ["#8389FF"])+ #expect(one.resolved(systemDark: false).colors == ["#8389FF", "#8389FF"] && one.resolved(systemDark: false).solid)+ #expect(close(one.resolved(systemDark: true).accent, "#01021F"))// In Light it is the same flat colour; in Dark one flat colour keeping its hue.#expect(SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "light").solid)let darkOne = SpaceThemeVariants.theme(key: ["#8389FF"], intensity: 0.5, noise: 0, appearance: "dark")diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/input/sidebar-auto-theme.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/input/sidebar-auto-theme.jsonnew file mode 100644index 0000000..93f2c8f--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/input/sidebar-auto-theme.json@@ -0,0 +1,228 @@+{+ "version": 1,+ "spaceOrder": [+ "A0000000-0000-0000-0000-000000000001",+ "A0000000-0000-0000-0000-000000000002",+ "A0000000-0000-0000-0000-000000000003"+ ],+ "spaces": [+ {+ "id": "A0000000-0000-0000-0000-000000000001",+ "title": "Editor Auto",+ "emoji": "🌗",+ "theme": {+ "colors": [+ "#8389FF",+ "#8389FF"+ ],+ "intensity": 0.5,+ "noise": 0,+ "appearance": "auto",+ "accent": "#8389FF",+ "solid": true,+ "key": [+ "#8389FF"+ ],+ "dark": {+ "colors": [+ "#2B2734",+ "#2B2734"+ ],+ "intensity": 1,+ "noise": 0,+ "vibrant": false,+ "accent": "#01021F",+ "solid": false+ }+ },+ "favoritesContainerID": "C0000000-0000-0000-0000-000000000011",+ "pinnedContainerID": "C0000000-0000-0000-0000-000000000012",+ "todayContainerID": "C0000000-0000-0000-0000-000000000013",+ "createdAt": "2026-11-06T08:00:00Z"+ },+ {+ "id": "A0000000-0000-0000-0000-000000000002",+ "title": "Short half",+ "emoji": "🌓",+ "theme": {+ "colors": [+ "#F8D558",+ "#FFF1B8"+ ],+ "intensity": 0.6,+ "noise": 0,+ "appearance": "auto",+ "accent": "#F8D558",+ "dark": {+ "colors": [+ "#101A3A",+ "#1E2C5C"+ ],+ "intensity": 0.9+ }+ },+ "favoritesContainerID": "C0000000-0000-0000-0000-000000000021",+ "pinnedContainerID": "C0000000-0000-0000-0000-000000000022",+ "todayContainerID": "C0000000-0000-0000-0000-000000000023",+ "createdAt": "2026-11-06T08:00:00Z"+ },+ {+ "id": "A0000000-0000-0000-0000-000000000003",+ "title": "Broken half",+ "emoji": "🌑",+ "theme": {+ "colors": [+ "#2861B3",+ "#2861B3"+ ],+ "intensity": 1,+ "noise": 0,+ "appearance": "auto",+ "dark": {+ "colors": 5+ }+ },+ "favoritesContainerID": "C0000000-0000-0000-0000-000000000031",+ "pinnedContainerID": "C0000000-0000-0000-0000-000000000032",+ "todayContainerID": "C0000000-0000-0000-0000-000000000033",+ "createdAt": "2026-11-06T08:00:00Z"+ }+ ],+ "items": [+ {+ "id": "C0000000-0000-0000-0000-000000000011",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "favorites": {+ "spaceID": "A0000000-0000-0000-0000-000000000001"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000012",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "pinned": {+ "spaceID": "A0000000-0000-0000-0000-000000000001"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000013",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "today": {+ "spaceID": "A0000000-0000-0000-0000-000000000001"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000021",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "favorites": {+ "spaceID": "A0000000-0000-0000-0000-000000000002"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000022",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "pinned": {+ "spaceID": "A0000000-0000-0000-0000-000000000002"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000023",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "today": {+ "spaceID": "A0000000-0000-0000-0000-000000000002"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000031",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "favorites": {+ "spaceID": "A0000000-0000-0000-0000-000000000003"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000032",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "pinned": {+ "spaceID": "A0000000-0000-0000-0000-000000000003"+ }+ }+ }+ }+ },+ {+ "id": "C0000000-0000-0000-0000-000000000033",+ "children": [],+ "isUnread": false,+ "createdAt": "2026-11-06T08:00:00Z",+ "data": {+ "container": {+ "_0": {+ "today": {+ "spaceID": "A0000000-0000-0000-0000-000000000003"+ }+ }+ }+ }+ }+ ]+}diff --git a/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/sidebar-auto-theme.json b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/sidebar-auto-theme.jsonnew file mode 100644index 0000000..5d234f7--- /dev/null+++ b/Packages/CraCore/Tests/CraCoreTests/Fixtures/Model/recorded/sidebar-auto-theme.json@@ -0,0 +1,251 @@+{+ "items" : [+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "favorites" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000001"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000011",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "pinned" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000001"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000012",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "today" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000001"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000013",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "favorites" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000002"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000021",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "pinned" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000002"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000022",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "today" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000002"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000023",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "favorites" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000003"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000031",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "pinned" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000003"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000032",+ "isUnread" : false+ },+ {+ "children" : [++ ],+ "createdAt" : "2026-11-06T08:00:00Z",+ "data" : {+ "container" : {+ "_0" : {+ "today" : {+ "spaceID" : "A0000000-0000-0000-0000-000000000003"+ }+ }+ }+ },+ "id" : "C0000000-0000-0000-0000-000000000033",+ "isUnread" : false+ }+ ],+ "spaceOrder" : [+ "A0000000-0000-0000-0000-000000000001",+ "A0000000-0000-0000-0000-000000000002",+ "A0000000-0000-0000-0000-000000000003"+ ],+ "spaces" : [+ {+ "createdAt" : "2026-11-06T08:00:00Z",+ "emoji" : "🌗",+ "favoritesContainerID" : "C0000000-0000-0000-0000-000000000011",+ "id" : "A0000000-0000-0000-0000-000000000001",+ "pinnedContainerID" : "C0000000-0000-0000-0000-000000000012",+ "theme" : {+ "accent" : "#8389FF",+ "appearance" : "auto",+ "colors" : [+ "#8389FF",+ "#8389FF"+ ],+ "dark" : {+ "accent" : "#01021F",+ "colors" : [+ "#2B2734",+ "#2B2734"+ ],+ "intensity" : 1,+ "noise" : 0,+ "solid" : false,+ "vibrant" : false+ },+ "intensity" : 0.5,+ "key" : [+ "#8389FF"+ ],+ "noise" : 0,+ "solid" : true,+ "vibrant" : false+ },+ "title" : "Editor Auto",+ "todayContainerID" : "C0000000-0000-0000-0000-000000000013"+ },+ {+ "createdAt" : "2026-11-06T08:00:00Z",+ "emoji" : "🌓",+ "favoritesContainerID" : "C0000000-0000-0000-0000-000000000021",+ "id" : "A0000000-0000-0000-0000-000000000002",+ "pinnedContainerID" : "C0000000-0000-0000-0000-000000000022",+ "theme" : {+ "accent" : "#F8D558",+ "appearance" : "auto",+ "colors" : [+ "#F8D558",+ "#FFF1B8"+ ],+ "dark" : {+ "colors" : [+ "#101A3A",+ "#1E2C5C"+ ],+ "intensity" : 0.9,+ "noise" : 0,+ "solid" : false,+ "vibrant" : false+ },+ "intensity" : 0.6,+ "noise" : 0,+ "solid" : false,+ "vibrant" : false+ },+ "title" : "Short half",+ "todayContainerID" : "C0000000-0000-0000-0000-000000000023"+ },+ {+ "createdAt" : "2026-11-06T08:00:00Z",+ "emoji" : "🌑",+ "favoritesContainerID" : "C0000000-0000-0000-0000-000000000031",+ "id" : "A0000000-0000-0000-0000-000000000003",+ "pinnedContainerID" : "C0000000-0000-0000-0000-000000000032",+ "theme" : {+ "appearance" : "auto",+ "colors" : [+ "#2861B3",+ "#2861B3"+ ],+ "intensity" : 1,+ "noise" : 0,+ "solid" : false,+ "vibrant" : false+ },+ "title" : "Broken half",+ "todayContainerID" : "C0000000-0000-0000-0000-000000000033"+ }+ ],+ "version" : 1+}\ No newline at end of filediff --git a/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift b/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swiftindex 0294c46..4e65d49 100644--- a/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift@@ -48,13 +48,27 @@ struct ModelFixtureTests {try decoder.decode(T.self, from: encoder.encode(value)) == value}- @Test(arguments: ["sidebar.json", "sidebar-legacy.json", "sidebar-stacked-icon.json"])+ @Test(arguments: ["sidebar.json", "sidebar-legacy.json", "sidebar-stacked-icon.json", "sidebar-auto-theme.json"])func sidebarLoadsAsRecorded(name: String) throws {let (loaded, recorded) = try Self.load(name, as: SidebarDocument.self)#expect(loaded == recorded)#expect(try Self.roundTrips(loaded))}+ /// Auto spaces keep both halves through a load (#155). A dark half without its optional fields+ /// gets them off, and one that can't be read is dropped with its space kept: until 0.1.33 either+ /// set the whole sidebar.json aside as corrupt.+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/155"))+ func autoSpacesKeepBothHalves() throws {+ let (loaded, _) = try Self.load("sidebar-auto-theme.json", as: SidebarDocument.self)+ #expect(loaded.spaces.map(\.title) == ["Editor Auto", "Short half", "Broken half"])+ #expect(loaded.spaces.map { $0.theme.followsSystem } == [true, true, true])+ #expect(loaded.spaces.map { $0.theme.dark != nil } == [true, true, false])+ for space in loaded.spaces.prefix(2) {+ #expect(!space.theme.resolved(systemDark: false).isDark && space.theme.resolved(systemDark: true).isDark)+ }+ }+/// 0.1.31's Edit Space… → Save wrote 🌱 beside an imported space's symbol (#205): the symbol/// stays and the emoji goes, so the sidebar draws one icon again.@Test func stackedSpaceIconLoadsAsItsSymbol() throws {diff --git a/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift b/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swiftindex 32edf55..b3aa392 100644--- a/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift+++ b/Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift@@ -34,14 +34,17 @@ struct SpaceColorPresetsTests {#expect(SpaceColorPresets.page(of: ["#123456"]) == nil)}- /// A new space starts on one colour, saved as Arc's one-dot (solid) theme, not a gradient.- @Test(arguments: 0..<9)- func newSpaceIsOneColour(index: Int) {- let theme = SpaceColorPresets.newSpaceTheme(index: index)- #expect(theme.key == [SpaceColorPresets.brand[index]])+ /// A new space starts on one colour (#170) on Auto, so it follows macOS like every Auto space+ /// (#155): the colour, flat, while macOS is light (a pastel of it when it reads dark) and the+ /// colour's hue, dark, while macOS is dark.+ @Test(.bug("https://github.com/VictorKildahl/cra/issues/155"), arguments: 0..<9)+ func newSpaceIsOneColourOnAuto(index: Int) {let hex = SpaceColorPresets.brand[index]- #expect(theme.solid && theme.colors == [hex, hex] && theme.dark == nil && !theme.followsSystem)- #expect(theme.isDark == (HexColor.luminance(hex)! < 0.45))+ let theme = SpaceColorPresets.newSpaceTheme(index: index)+ #expect(theme.key == [hex] && theme.appearance == "auto" && theme.dark != nil)+ let light = theme.resolved(systemDark: false), dark = theme.resolved(systemDark: true)+ #expect(light.solid && light.colors.count == 2 && light.colors[0] == light.colors[1] && !light.isDark)+ #expect(dark.colors.count == 2 && dark.colors[0] == dark.colors[1] && dark.isDark)}/// Arc's pairs: each Brand colour with the second colour Arc saved for it, which keeps roughlydiff --git a/Sources/Cra/App/AppDelegate.swift b/Sources/Cra/App/AppDelegate.swiftindex bc2fbe0..21a115c 100644--- a/Sources/Cra/App/AppDelegate.swift+++ b/Sources/Cra/App/AppDelegate.swift@@ -722,6 +722,21 @@ final class AppDelegate: NSObject, NSApplicationDelegate, NSMenuItemValidation {NSApp.appearance = v == "system" ? nil : NSAppearance(named: v == "dark" ? .darkAqua : .aqua)return}+ // themeShown=<label>: which half each window draws now (the space's theme, the window content+ // and the sidebar), without redrawing first, so a missed macOS switch shows (#155).+ if let label = dict["themeShown"] {+ func sidebar(in v: NSView) -> SidebarView? {+ v as? SidebarView ?? v.subviews.lazy.compactMap { sidebar(in: $0) }.first+ }+ func side(_ dark: Bool) -> String { dark ? "dark" : "light" }+ for m in mainWindows {+ let space = m.focusedSpace+ let drawn = m.window?.contentView.flatMap(sidebar(in:)).map { side($0.palette.isDark) } ?? "-"+ NSLog("Cra theme shown %@: space=%@ follows=%d theme=%@ shell=%@ sidebar=%@", label, space.title, space.theme.followsSystem ? 1 : 0,+ side(space.theme.shown.isDark), side(m.shell.isDarkTheme), drawn)+ }+ return+ }if dict["relaunch"] != nil { relaunch(); return }if dict["quit"] != nil { NSApp.terminate(nil); return }if let t = dict["selectTab"].flatMap(UUID.init(uuidString:)) { store.selectTab(t, window: main.windowID); return }diff --git a/Sources/Cra/UI/Sidebar/List/SidebarView.swift b/Sources/Cra/UI/Sidebar/List/SidebarView.swiftindex 46bfcb2..848af98 100644--- a/Sources/Cra/UI/Sidebar/List/SidebarView.swift+++ b/Sources/Cra/UI/Sidebar/List/SidebarView.swift@@ -21,7 +21,8 @@ final class SidebarView: NSView {private let bannerHost = UpdateBannerView()private let dock: SpaceDockViewprivate var libraryHost: LibraryView?- private var palette: SpacePalette+ /// The palette drawn now; the theme-shown scenario hook reads it (#155).+ private(set) var palette: SpacePaletteprivate var lastSpaceID: UUID?private var shownTheme: SpaceTheme?private var shownLibrary: LibraryPage?diff --git a/Sources/Cra/UI/Windows/SpaceStyleEditor.swift b/Sources/Cra/UI/Windows/SpaceStyleEditor.swiftindex ab9f00c..ea6f7be 100644--- a/Sources/Cra/UI/Windows/SpaceStyleEditor.swift+++ b/Sources/Cra/UI/Windows/SpaceStyleEditor.swift@@ -9,8 +9,8 @@ import SwiftUI/// for the intensity and a dotted dial for the grain. Every change goes to `onChange` at once (the/// caller previews it); nothing here writes. Like Arc's editor state it keeps the pad's colours,/// the intensity, the grain and Auto / Light / Dark, and builds the theme from them-/// (SpaceThemeVariants): one colour is Arc's one-dot theme, two or three a gradient whose Auto-/// gets a light and a dark half.+/// (SpaceThemeVariants): one colour is Arc's one-dot fill, two or three a gradient, and Auto+/// always gets a light and a dark half (#155).struct SpaceStyleEditor: View {@State private var theme: SpaceTheme@State private var pad: PadStatediff --git a/Tests/Scenarios/auto-theme.scenario b/Tests/Scenarios/auto-theme.scenarionew file mode 100644index 0000000..6ab34fb--- /dev/null+++ b/Tests/Scenarios/auto-theme.scenario@@ -0,0 +1,27 @@+# An Auto space follows macOS live, both ways, in the window content and the sidebar; a Light+# space keeps its look (#155). 0.1.30-0.1.32 saved the editor's one-colour Auto as a fixed theme.+# systemAppearance flips the app's appearance without touching the Mac's own setting.+budget rss=600 stalls50=10+seed settings.json {"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true}+seed sidebar.json {"version":1,"spaceOrder":["A0000000-0000-0000-0000-000000000001","A0000000-0000-0000-0000-000000000002"],"spaces":[{"id":"A0000000-0000-0000-0000-000000000001","title":"Auto","emoji":"🌗","theme":{"colors":["#8389FF","#8389FF"],"intensity":0.5,"noise":0,"appearance":"auto","accent":"#8389FF","solid":true,"key":["#8389FF"],"dark":{"colors":["#2B2734","#2B2734"],"intensity":1,"noise":0,"vibrant":false,"accent":"#01021F","solid":false}},"favoritesContainerID":"C0000000-0000-0000-0000-000000000011","pinnedContainerID":"C0000000-0000-0000-0000-000000000012","todayContainerID":"C0000000-0000-0000-0000-000000000013","createdAt":"2026-11-06T08:00:00Z"},{"id":"A0000000-0000-0000-0000-000000000002","title":"Light","emoji":"☀️","theme":{"colors":["#8389FF","#8389FF"],"intensity":0.5,"noise":0,"appearance":"light","accent":"#8389FF","solid":true,"key":["#8389FF"]},"favoritesContainerID":"C0000000-0000-0000-0000-000000000021","pinnedContainerID":"C0000000-0000-0000-0000-000000000022","todayContainerID":"C0000000-0000-0000-0000-000000000023","createdAt":"2026-11-06T08:00:00Z"}],"items":[{"id":"C0000000-0000-0000-0000-000000000011","children":[],"isUnread":false,"createdAt":"2026-11-06T08:00:00Z","data":{"container":{"_0":{"favorites":{"spaceID":"A0000000-0000-0000-0000-000000000001"}}}}},{"id":"C0000000-0000-0000-0000-000000000012","children":[],"isUnread":false,"createdAt":"2026-11-06T08:00:00Z","data":{"container":{"_0":{"pinned":{"spaceID":"A0000000-0000-0000-0000-000000000001"}}}}},{"id":"C0000000-0000-0000-0000-000000000013","children":[],"isUnread":false,"createdAt":"2026-11-06T08:00:00Z","data":{"container":{"_0":{"today":{"spaceID":"A0000000-0000-0000-0000-000000000001"}}}}},{"id":"C0000000-0000-0000-0000-000000000021","children":[],"isUnread":false,"createdAt":"2026-11-06T08:00:00Z","data":{"container":{"_0":{"favorites":{"spaceID":"A0000000-0000-0000-0000-000000000002"}}}}},{"id":"C0000000-0000-0000-0000-000000000022","children":[],"isUnread":false,"createdAt":"2026-11-06T08:00:00Z","data":{"container":{"_0":{"pinned":{"spaceID":"A0000000-0000-0000-0000-000000000002"}}}}},{"id":"C0000000-0000-0000-0000-000000000023","children":[],"isUnread":false,"createdAt":"2026-11-06T08:00:00Z","data":{"container":{"_0":{"today":{"spaceID":"A0000000-0000-0000-0000-000000000002"}}}}}]}+cra://debug?systemAppearance=light+wait 1+cra://debug?themeShown=auto-light+expect-log Cra theme shown auto-light: space=Auto follows=1 theme=light shell=light sidebar=light+cra://debug?systemAppearance=dark+wait 1+cra://debug?themeShown=auto-dark+expect-log Cra theme shown auto-dark: space=Auto follows=1 theme=dark shell=dark sidebar=dark+snapshot SpaceHeaderView auto-theme-header-dark+cra://debug?systemAppearance=light+wait 1+cra://debug?themeShown=auto-light-again+expect-log Cra theme shown auto-light-again: space=Auto follows=1 theme=light shell=light sidebar=light+snapshot SpaceHeaderView auto-theme-header-light+cra://action/space2+wait 1+cra://debug?systemAppearance=dark+wait 1+cra://debug?themeShown=light-space-on-dark+expect-log Cra theme shown light-space-on-dark: space=Light follows=0 theme=light shell=light sidebar=light+cra://debug?systemAppearance=systemdiff --git a/Tests/Snapshots/auto-theme-header-dark.png b/Tests/Snapshots/auto-theme-header-dark.pngnew file mode 100644index 0000000..0b79a47Binary files /dev/null and b/Tests/Snapshots/auto-theme-header-dark.png differdiff --git a/Tests/Snapshots/auto-theme-header-light.png b/Tests/Snapshots/auto-theme-header-light.pngnew file mode 100644index 0000000..80f8edcBinary files /dev/null and b/Tests/Snapshots/auto-theme-header-light.png differdiff --git a/Tests/promises.lock b/Tests/promises.locknew file mode 100644index 0000000..9e4ce3b--- /dev/null+++ b/Tests/promises.lock@@ -0,0 +1,9 @@+# Tests that pin what a closed issue shipped (scripts/promises.py). Each line: issue, test, hash+# of its code. Change a test here only when the promise changes on purpose: name the issue and why+# in the commit, and tell its reporter. Regenerate with scripts/promises.py --update.+#155 Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift::autoShowsTheHalfMacOSAsksFor 73a172a01086+#155 Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift::everySwatchOnAutoFollowsMacOS 2abd1f76b828+#155 Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift::everySwatchOnLightOrDarkKeepsOneLook 95d16ff2c954+#155 Packages/CraCore/Tests/CraCoreTests/ModelFixtureTests.swift::autoSpacesKeepBothHalves 89e5047a5e96+#155 Packages/CraCore/Tests/CraCoreTests/SpaceColorPresetsTests.swift::newSpaceIsOneColourOnAuto 32095d76196a+#171 Packages/CraCore/Tests/CraCoreTests/ArcThemeImportTests.swift::autoThemeWithOneHalfKeepsItsLook 6162547ce294diff --git a/docs/arc-reverse-engineering.md b/docs/arc-reverse-engineering.mdindex 5ebff5d..2d3180d 100644--- a/docs/arc-reverse-engineering.md+++ b/docs/arc-reverse-engineering.md@@ -2877,8 +2877,11 @@ that waits 3 s before answering and then serves a page whose image takes 5 s.switch redraws at once. Arc imports keep both halves. The editor builds halves from its pad (`SpaceTheme.key`) with`SpaceThemeVariants`: the light half is the pad's colours (lifted to HSL lightness 0.9 only when they read dark),the dark half keeps their hue at HSL lightness 0.064, drawn like an imported dark half (27 % over #2B2632). An- Auto theme with one set of colours (saved before, or from the Edit Space sheet or Zen) stays on the side they suit- whatever macOS shows, and an Arc `single` without `contentOverBackgroundAppearance` imports as that side (#171).+ Auto theme with one set of colours (saved before 0.1.29, or from Zen) stays on the side they suit whatever macOS+ shows, and an Arc `single` without `contentOverBackgroundAppearance` imports as that side (#171).+- Cra deviates on purpose (Victor, 6 Nov 2026, #155): the editor's Auto always builds both halves, one colour too.+ Arc saves a swatch picked on Auto as a fixed `single`; Cra copied that in 0.1.30–0.1.32, and a space set to Auto+ stopped following macOS. Pinned by `everySwatchOnAutoFollowsMacOS` and the `auto-theme` scenario.- [?] Not worked out: how Arc's editor maps a picked colour to its halves (the pad's `lightnessRange` and the biasvalue). Cra's halves are fitted to Arc's default theme only.diff --git a/docs/testing.md b/docs/testing.mdindex 81225ab..c03a685 100644--- a/docs/testing.md+++ b/docs/testing.md@@ -21,6 +21,13 @@ Commands for each piece are in [development.md](development.md#tests).6. **Never assert on a fake's bookkeeping alone.** A test whose only check is "the fakerecorded a call" tests the fake.7. **A flaky test is rewritten on the clock or deleted**, never retried or given a sleep.+8. **What a closed issue shipped is pinned.** The test that proves an issue's fix carries+ `.bug("https://github.com/VictorKildahl/cra/issues/<n>")`, and `Tests/promises.lock` holds a+ hash of each such test (`scripts/promises.py`, run by `scripts/test.sh` and by a hook before+ every `git push`). Changing, renaming or deleting one fails until `scripts/promises.py --update`;+ do that only when the issue's behaviour is meant to change, say why in the commit and tell the+ reporter. 0.1.30 rewrote the #155 test together with the change that broke it, and nothing+ failed until the reporter wrote back.## Layers@@ -102,6 +109,10 @@ folder, behind your windows (`CRA_TEST_BACKGROUND`), with the fixture pages serv127.0.0.1. Logs, hitch log and snapshots land in `build/scenarios/<name>/`. Adding a journeyis a text file; the invariants come for free.+`auto-theme` flips the app between light and dark (`cra://debug?systemAppearance=`) and reads+which half each window draws (`cra://debug?themeShown=<label>`): an Auto space must switch its+window content and sidebar both ways, and a Light one must not (#155).+`fullscreen` takes over a Space and runs only with `CRA_SCENARIO_SCREEN=1` (CI does).`CRA_FLAGS=backdrop=material` runs any scenario on the sidebar's `NSVisualEffectView` pathinstead of the private `CABackdropLayer` one (`FeatureFlags`); nightly runs both, so a macOSdiff --git a/scripts/check-promises-hook.sh b/scripts/check-promises-hook.shnew file mode 100755index 0000000..e366f12--- /dev/null+++ b/scripts/check-promises-hook.sh@@ -0,0 +1,24 @@+#!/usr/bin/env bash+# Claude Code PreToolUse hook (Bash): before a `git push`, checks that the commit being pushed+# keeps every test that pins a shipped issue's behaviour as Tests/promises.lock has it+# (scripts/promises.py). Blocks (exit 2) when one changed without the lock. CI runs the same check+# through scripts/test.sh, but after the push; sessions push straight to main.+set -euo pipefail++input="$(cat)"+command="$(jq -r '.tool_input.command // empty' <<<"$input")"+# Only an actual `git push` (at the start of a command, maybe after VAR=… prefixes or `git -C dir`).+grep -qE '(^|[;&|(]|\$\()[[:space:]]*([A-Za-z_][A-Za-z0-9_]*=("[^"]*"|[^[:space:]]+)[[:space:]]+)*git[[:space:]]+(-C[[:space:]]+[^[:space:]]+[[:space:]]+)?push\b' <<<"$command" || exit 0++# The repository the push runs in: `git -C dir`, else a leading `cd dir &&`, else the hook's cwd.+dir="$(jq -r '.cwd // empty' <<<"$input")"+if [[ "$command" =~ git[[:space:]]+-C[[:space:]]+([^[:space:]]+)[[:space:]]+push ]]; then dir="${BASH_REMATCH[1]}"+elif [[ "$command" =~ ^[[:space:]]*cd[[:space:]]+([^[:space:];&]+) ]]; then dir="${BASH_REMATCH[1]}"; fi+dir="${dir/#\~/$HOME}"; dir="${dir//\"/}"; dir="${dir//\'/}"+repo="$(git -C "${dir:-.}" rev-parse --show-toplevel 2>/dev/null)" || exit 0+[[ -x "$repo/scripts/promises.py" ]] || exit 0++if ! out="$("$repo/scripts/promises.py" --rev HEAD 2>&1)"; then+ echo "$out" >&2+ exit 2+fidiff --git a/scripts/promises.py b/scripts/promises.pynew file mode 100755index 0000000..22af72e--- /dev/null+++ b/scripts/promises.py@@ -0,0 +1,180 @@+#!/usr/bin/env python3+"""What a closed issue shipped stays shipped, unless someone changes it on purpose (GitHub #155).++A test that pins a shipped issue's behaviour carries Swift Testing's bug trait:++ @Test(.bug("https://github.com/VictorKildahl/cra/issues/155"), arguments: ...)++Tests/promises.lock records each such test with its issue and a hash of its code (comments and+whitespace left out). A tagged test that changes, is renamed or is deleted fails this check, and so+does a new one, until the lock is updated:++ scripts/promises.py check the working tree (scripts/test.sh runs it)+ scripts/promises.py --rev HEAD check a commit instead (the push hook, check-promises-hook.sh)+ scripts/promises.py --update take the tagged tests as they are now++Update the lock only when the promise itself changes: say in the commit which issue's behaviour+changes and why, and tell the issue's reporter. Why: 0.1.30 (#170, #171) changed the theme editor+so a space set to Auto stopped following macOS, rewrote the #155 test to match, and every suite+stayed green until the reporter wrote back.+"""+import hashlib+import pathlib+import re+import subprocess+import sys++ROOT = pathlib.Path(__file__).resolve().parent.parent+LOCK = ROOT / "Tests" / "promises.lock"+SOURCES = ["Packages/CraCore/Tests", "Tests"]+ISSUE = re.compile(r"github\.com/VictorKildahl/cra/issues/(\d+)")+HEADER = """\+# Tests that pin what a closed issue shipped (scripts/promises.py). Each line: issue, test, hash+# of its code. Change a test here only when the promise changes on purpose: name the issue and why+# in the commit, and tell its reporter. Regenerate with scripts/promises.py --update.+"""+++def skip_string(s: str, i: int) -> int:+ """Index just past the string literal whose opening quote (or first #) is at i."""+ hashes = 0+ while s[i] == "#":+ hashes += 1+ i += 1+ if s.startswith('"""', i):+ close = '"""' + "#" * hashes+ end = s.find(close, i + 3)+ return len(s) if end < 0 else end + len(close)+ close = '"' + "#" * hashes+ i += 1+ while i < len(s):+ if s[i] == "\\" and hashes == 0:+ i += 2+ continue+ if s.startswith(close, i):+ return i + len(close)+ if s[i] == "\n": # unterminated single-line string: give up on it+ return i+ i += 1+ return i+++def skip_comment(s: str, i: int) -> int:+ if s.startswith("//", i):+ end = s.find("\n", i)+ return len(s) if end < 0 else end+ end = s.find("*/", i + 2)+ return len(s) if end < 0 else end + 2+++def balanced(s: str, i: int, open_: str, close: str) -> int:+ """Index just past the bracket matching the one at i, skipping strings and comments."""+ depth = 0+ while i < len(s):+ c = s[i]+ if c == '"' or (c == "#" and re.match(r'#+"', s[i:])):+ i = skip_string(s, i)+ continue+ if s.startswith("//", i) or s.startswith("/*", i):+ i = skip_comment(s, i)+ continue+ if c == open_:+ depth += 1+ elif c == close:+ depth -= 1+ if depth == 0:+ return i + 1+ i += 1+ raise ValueError("unbalanced")+++def normalise(code: str) -> str:+ code = re.sub(r"^\s*//.*$", "", code, flags=re.M)+ return " ".join(code.split())+++def files(rev):+ """(repo-relative path, text) of every Swift test file, in the working tree or at a commit."""+ if rev is None:+ for base in SOURCES:+ for path in sorted((ROOT / base).rglob("*.swift")):+ if ".build" not in path.parts:+ yield path.relative_to(ROOT).as_posix(), path.read_text()+ return+ names = git("ls-tree", "-r", "--name-only", rev, "--", *SOURCES).splitlines()+ for name in sorted(names):+ if name.endswith(".swift") and "/.build/" not in name:+ yield name, git("show", f"{rev}:{name}")+++def git(*args):+ return subprocess.run(["git", "-C", str(ROOT), *args], check=True, capture_output=True, text=True).stdout+++def promises(rev=None):+ """(issue, test id, hash) for every tagged test."""+ found = []+ for rel, s in files(rev):+ for m in re.finditer(r"@Test\s*\(", s):+ attr_end = balanced(s, m.end() - 1, "(", ")")+ issues = sorted({int(n) for n in ISSUE.findall(s[m.start():attr_end])})+ if ".bug(" not in s[m.start():attr_end] or not issues:+ continue+ fn = re.compile(r"\s*func\s+(\w+)").match(s, attr_end)+ if not fn:+ sys.exit(f"promises: {rel}: a .bug test whose func doesn't follow its @Test(...)")+ body_end = balanced(s, s.index("{", fn.end()), "{", "}")+ digest = hashlib.sha256(normalise(s[m.start():body_end]).encode()).hexdigest()[:12]+ for issue in issues:+ found.append((issue, f"{rel}::{fn.group(1)}", digest))+ return found+++def read_lock(rev=None):+ entries = {}+ if rev is not None:+ try:+ text = git("show", f"{rev}:{LOCK.relative_to(ROOT).as_posix()}")+ except subprocess.CalledProcessError:+ text = ""+ else:+ text = LOCK.read_text() if LOCK.exists() else ""+ for line in text.splitlines():+ if line.strip() and not line.startswith("# "):+ issue, test, digest = line.split()+ entries[(int(issue.lstrip("#")), test)] = digest+ return entries+++def main():+ args = sys.argv[1:]+ rev = args[args.index("--rev") + 1] if "--rev" in args else None+ current = promises(rev)+ if "--update" in args:+ lines = [f"#{issue:<5} {test} {digest}" for issue, test, digest in sorted(current)]+ LOCK.write_text(HEADER + "\n".join(lines) + "\n")+ print(f"promises: {len(current)} tests pinned for {len({i for i, _, _ in current})} issues")+ return 0+ locked = read_lock(rev)+ now = {(issue, test): digest for issue, test, digest in current}+ problems = []+ for key, digest in sorted(now.items()):+ if key not in locked:+ problems.append(f"#{key[0]} {key[1]} is new: lock it with scripts/promises.py --update")+ elif locked[key] != digest:+ problems.append(f"#{key[0]} {key[1]} changed")+ for key in sorted(set(locked) - set(now)):+ problems.append(f"#{key[0]} {key[1]} is gone (deleted, renamed or untagged)")+ if problems:+ print("promises: tests that pin a shipped issue's behaviour differ from Tests/promises.lock:")+ for p in problems:+ print(f" {p}")+ print("If the issue's behaviour is meant to change: scripts/promises.py --update, say in the commit")+ print("which issue changes and why, and tell its reporter. Otherwise put the test back.")+ return 1+ print(f"promises: {len(now)} tests pinned for {len({i for i, _ in now})} issues, unchanged")+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/scripts/test.sh b/scripts/test.shindex 739ca16..c18c455 100755--- a/scripts/test.sh+++ b/scripts/test.sh@@ -15,6 +15,7 @@ suite() {}suite "CraCore" swift test --package-path Packages/CraCore+suite "Shipped-issue tests" scripts/promises.pyif [ "${1:-}" != core ]; thensuite "Browser manager" Tests/test-browser-manager.shsuite "Floating sidebar" scripts/test-floating-sidebar.sh