Skip to main content

greengate_runtime/
names.rs

1//! Every name the tool says about itself, in one place (ADR-0064
2//! `harness.renames`, plan "amont ships as greengate").
3//!
4//! Messages, usage text, error prefixes, `--version` lines and command hints
5//! are built from these, never from a literal: a later name is one change
6//! here. The names test (`crates/greengate/tests/it/names.rs`) fails on a new
7//! literal `"amont "`, `"amont: "` or `"amont-fleet"` in any other source.
8//!
9//! The names the tool READS and WRITES are here too since greengate 4.0
10//! (plan "greengate 4.0 renames its data names", a hard rename): the
11//! `GREENGATE_` environment, the `greengate.` config keys, the state under
12//! `$GIT_DIR` and the common dir, and the ledgers' headers. greengate 3.x's
13//! spellings live only in `migrate.rs`, which moves them once; the names
14//! test fails on an old data name anywhere else. Kept on purpose: the notes
15//! namespaces (the legacy `amont-*` set, read beside the green one: plan 3a-3), the shim placeholder, and
16//! the binary aliases above.
17//!
18//! In a format string, name the constant inline: `eprintln!("{BIN}: …")`.
19//! For a `&'static str` built at compile time, use the [`bin!`] macro with
20//! `concat!`.
21
22/// The hook binary's name as a literal, for `concat!` in a `&'static str`.
23#[doc(hidden)]
24#[macro_export]
25macro_rules! bin {
26    () => {
27        "greengate"
28    };
29}
30
31/// The fleet binary's name as a literal, for `concat!` in a `&'static str`.
32#[doc(hidden)]
33#[macro_export]
34macro_rules! fleet_bin {
35    () => {
36        "greengate-fleet"
37    };
38}
39
40/// The product's name, as it introduces itself.
41pub const PRODUCT: &str = "greengate";
42
43/// The hook binary.
44pub const BIN: &str = bin!();
45
46/// The fleet binary.
47pub const FLEET_BIN: &str = fleet_bin!();
48
49/// The hook binary's old name, still installed as an alias (a copy).
50pub const OLD_BIN: &str = "amont";
51
52/// The fleet binary's old name, still installed as an alias (a copy).
53pub const OLD_FLEET_BIN: &str = "amont-fleet";
54
55/// The repository the releases come from.
56pub const REPO: &str = "greenharness/greengate";
57
58/// The one-line installer for Linux and macOS.
59pub const INSTALLER_URL: &str =
60    "https://raw.githubusercontent.com/greenharness/greengate/main/install/install.sh";
61
62/// The crate `cargo install` takes.
63pub const CRATE: &str = "greengate";
64
65/// The npm package.
66pub const NPM_PACKAGE: &str = "@greenharness/greengate";
67
68/// The Homebrew formula, tap-qualified.
69pub const BREW_FORMULA: &str = "fredericrous/tap/greengate";
70
71/// The git config namespace every key lives in (`greengate.timeout`).
72pub const CONFIG_PREFIX: &str = "greengate.";
73
74/// The environment namespace a host key answers to (`GREENGATE_TIMEOUT`).
75pub const ENV_PREFIX: &str = "GREENGATE";
76
77/// The folder of state under `$GIT_DIR` and the common dir (logs, land
78/// receipts, pending detached runs).
79pub const STATE_DIR: &str = "greengate";
80
81/// The tree cache under `$GIT_DIR`.
82pub const TREE_CACHE: &str = "greengate-cache";
83
84/// Where the unstaged changes are parked during a check.
85pub const HELD_STORE: &str = "greengate-held";
86
87/// A held copy a mid-check edit displaced.
88pub const PRESERVED_STORE: &str = "greengate-preserved";
89
90/// The bypass ledger, and its header.
91pub const BYPASS_LEDGER: &str = "greengate-bypasses";
92pub const BYPASS_FORMAT: &str = "greengate-bypass-v1";
93
94/// The downgrade ledger, and its header.
95pub const DOWNGRADE_LEDGER: &str = "greengate-downgrades";
96pub const DOWNGRADE_FORMAT: &str = "greengate-downgrade-v1";
97
98/// The waves ledger, and its header.
99pub const WAVES_LEDGER: &str = "greengate-waves";
100pub const WAVES_FORMAT: &str = "greengate-waves-v1";
101
102/// A rehearsal's state file, its log, and the state's header.
103pub const REHEARSAL_STATE: &str = "greengate-rehearsal";
104pub const REHEARSAL_LOG: &str = "greengate-rehearsal.log";
105pub const REHEARSAL_FORMAT: &str = "greengate-rehearsal-v1";
106
107/// The cold-cache warm worker's log under `$GIT_DIR`.
108pub const WARM_LOG: &str = "greengate-warm.log";
109
110/// The markers around a pack's block in the manifest, and the stem messages
111/// quote.
112pub const PACK_STEM: &str = "greengate:pack";
113pub const PACK_START: &str = "# greengate:pack:start";
114pub const PACK_END: &str = "# greengate:pack:end";
115
116/// The `format` field of `greengate check --format json`.
117pub const CHECK_FORMAT: &str = "greengate-check-v1";
118
119/// The inline comment that waives a secret finding on its line.
120pub const ALLOW_SECRET: &str = "greengate:allow-secret";
121
122/// The message of the throwaway commit made for a stamped tree.
123pub const STAMP_MESSAGE: &str = concat!(bin!(), " stamps");
124
125/// The committed audit waivers file.
126pub const AUDIT_WAIVERS: &str = ".greengate-audit-waivers";
127
128/// The notes ref the release audit caches its verdicts in (local, never
129/// pushed), and the header of each note.
130pub const AUDIT_REF: &str = "greengate-audit";
131pub const AUDIT_FORMAT: &str = "greengate-audit-v1";
132
133/// The version-skew marker, and its header.
134pub const SKEW_MARKER: &str = "greengate-skew";
135pub const SKEW_FORMAT: &str = "greengate-skew-v1";
136
137/// The held store's index header.
138pub const HELD_FORMAT: &str = "greengate-held-v1";
139
140/// The pre-commit → post-commit gate marker under `$GIT_DIR`. Its content
141/// is the notes format (`greengate-gate-v1`, plan 3a-3 Phase 4).
142pub const GATE_MARKER: &str = "greengate-gate";
143
144/// The committed manifest a repository declares its checks in.
145pub const MANIFEST: &str = "greengate.conf";
146
147/// The file a pack repository declares its rows in.
148pub const PACK_FILE: &str = "greengate.pack";
149
150/// The markers around the block greengate generates in AGENTS.md and the
151/// CLAUDE.md pointer.
152pub const AGENTS_START: &str = "<!-- greengate:start -->";
153pub const AGENTS_END: &str = "<!-- greengate:end -->";
154
155/// The `list --json` envelope. greenpiste and relais read it and the old
156/// `amont-list-v1` alike, from greenpiste 3.30.0 and relais 0.54.0.
157pub const LIST_FORMAT: &str = "greengate-list-v1";
158
159/// The migration's lock and its done-marker, in the common dir.
160pub const MIGRATE_LOCK: &str = "greengate-migrate.lock";
161pub const MIGRATED_MARKER: &str = "greengate-migrated";
162
163/// The marker `greengate migrate --reverse` leaves in the common dir: the
164/// first-run migration stands down until it is gone, so a 4.0 hook does
165/// not move a rolled-back repository forward again before 3.x is installed.
166pub const REVERSED_MARKER: &str = "greengate-reversed";
167
168/// The name this tool holds a host slot under (`greengate slots`).
169pub const SLOT_HOLDER: &str = "greengate";
170
171/// The label every Job and Workflow of one run carries, read by `collect`
172/// and the batched cluster reads.
173pub const RUN_LABEL: &str = "greengate.run";
174
175/// The annotations naming a cluster Job's gate and tree.
176pub const GATE_ANNOTATION: &str = "greengate.dev/gate";
177pub const TREE_ANNOTATION: &str = "greengate.dev/tree";
178
179// The Kubernetes names below are a contract with homelab's
180// `apps/greengate-gates`, which must define them; only the namespace can be
181// overridden (`greengate.cluster.namespace`). A change to any of them follows
182// the plan's two-change order: homelab adds the new name, then a release.
183
184/// The namespace cluster gates run in, unless `greengate.cluster.namespace`
185/// names another (homelab `apps/greengate-gates`).
186pub const CLUSTER_NAMESPACE: &str = "greengate-gates";
187/// `app.kubernetes.io/managed-by` on every Job and Workflow.
188pub const MANAGED_BY: &str = "greengate";
189/// A cluster Job's name before its slot number.
190pub const JOB_PREFIX: &str = "greengate-gate-slot-";
191/// A detached Workflow's name before its run label.
192pub const WORKFLOW_PREFIX: &str = "greengate-rh-";
193/// The ServiceAccount a detached Workflow's pods run as.
194pub const EXECUTOR_ACCOUNT: &str = "greengate-gate-executor";
195/// The Secret holding the snapshot repository's read token.
196pub const READ_TOKEN_SECRET: &str = "greengate-bot-read-token";
197/// The author and committer name of the commits this tool writes: a cluster
198/// gate's throwaway commit and a detached run's snapshot.
199pub const GIT_AUTHOR: &str = "greengate";
200/// Their email.
201pub const GIT_EMAIL: &str = "greengate@localhost";
202
203/// greengate 3.x's names: what `migrate` moves, and the committed names
204/// (manifest, pack, markers) read until the fleet sweep. Kept here, beside
205/// the new ones, so no module depends on the migration to know them; the
206/// census (Phase 6) removes the read-only ones.
207pub mod old {
208    /// The config namespace.
209    pub const CONFIG_PREFIX: &str = "amont.";
210    /// The environment variables' prefix.
211    pub const ENV_PREFIX: &str = "AMONT_";
212    /// greenpiste's own keys under that namespace: not greengate's to move.
213    pub const FOREIGN_PREFIX: &str = "amont.agent.";
214    /// greenpiste's own environment variables: not greengate's to move.
215    pub const FOREIGN_ENV_PREFIX: &str = "AMONT_AGENT_";
216    /// The held store, never moved (see `migrate`'s module doc).
217    pub const HELD_STORE: &str = "amont-held";
218    /// The held store's index header, which `greengate restore` still reads.
219    pub const HELD_FORMAT: &str = "amont-held-v1";
220    /// The namespace greengate 3.x's homelab cutover ran in.
221    pub const CLUSTER_NAMESPACE: &str = "amont-gates";
222    /// The folder of state greengate 3.x kept in the common dir.
223    pub const STATE_DIR: &str = "amont";
224    /// The committed manifest before 4.0: read when `greengate.conf` is
225    /// absent, until the fleet sweep has renamed every repository's (the
226    /// census removes that read).
227    pub const MANIFEST: &str = "amont.conf";
228    /// A pack repository's file before 4.0. Read whenever `greengate.pack`
229    /// is absent: a vendored pin at an older revision only ever has this one.
230    pub const PACK_FILE: &str = "amont.pack";
231    /// The hook shim's placeholder before 4.3. The frozen amont 2.3.1 shim
232    /// the fleet still recognises carries it.
233    pub const SHIM_PLACEHOLDER: &str = "__AMONT_BIN__";
234    /// The audit waivers file before 4.3: read when the new one is absent,
235    /// until the census (`greengate migrate --tracked` renames it).
236    pub const AUDIT_WAIVERS: &str = ".amont-audit-waivers";
237    /// The audit cache ref before 4.3, deleted by `migrate`.
238    pub const AUDIT_REF: &str = "amont-audit";
239    /// The inline secret waiver before 4.3: it waives nothing any more.
240    pub const ALLOW_SECRET: &str = "amont:allow-secret";
241    /// The pack block stem and markers before 4.3, read until the census.
242    pub const PACK_STEM: &str = "amont:pack";
243    pub const PACK_START: &str = "# amont:pack:start";
244    pub const PACK_END: &str = "# amont:pack:end";
245    /// The AGENTS.md markers before 4.0, read until the sweep.
246    pub const AGENTS_START: &str = "<!-- amont:start -->";
247    pub const AGENTS_END: &str = "<!-- amont:end -->";
248}
249
250#[cfg(test)]
251mod tests {
252    use super::*;
253
254    #[test]
255    fn the_macros_and_the_constants_agree() {
256        assert_eq!(BIN, PRODUCT);
257        assert_eq!(FLEET_BIN, concat!(bin!(), "-fleet"));
258        assert_eq!(CRATE, BIN);
259        assert!(NPM_PACKAGE.ends_with(BIN));
260        assert!(BREW_FORMULA.ends_with(BIN));
261        assert!(INSTALLER_URL.contains(REPO));
262    }
263}