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 (`refs/notes/amont-*`, 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 version-skew marker, and its header.
111pub const SKEW_MARKER: &str = "greengate-skew";
112pub const SKEW_FORMAT: &str = "greengate-skew-v1";
113
114/// The held store's index header.
115pub const HELD_FORMAT: &str = "greengate-held-v1";
116
117/// The pre-commit → post-commit gate marker under `$GIT_DIR`. Its content
118/// keeps the notes format (`amont-gate-v1`), which plan 3a-3 renames.
119pub const GATE_MARKER: &str = "greengate-gate";
120
121/// The committed manifest a repository declares its checks in.
122pub const MANIFEST: &str = "greengate.conf";
123
124/// The file a pack repository declares its rows in.
125pub const PACK_FILE: &str = "greengate.pack";
126
127/// The markers around the block greengate generates in AGENTS.md and the
128/// CLAUDE.md pointer.
129pub const AGENTS_START: &str = "<!-- greengate:start -->";
130pub const AGENTS_END: &str = "<!-- greengate:end -->";
131
132/// The `list --json` envelope. greenpiste and relais read it and the old
133/// `amont-list-v1` alike, from greenpiste 3.30.0 and relais 0.54.0.
134pub const LIST_FORMAT: &str = "greengate-list-v1";
135
136/// The migration's lock and its done-marker, in the common dir.
137pub const MIGRATE_LOCK: &str = "greengate-migrate.lock";
138pub const MIGRATED_MARKER: &str = "greengate-migrated";
139
140/// The marker `greengate migrate --reverse` leaves in the common dir: the
141/// first-run migration stands down until it is gone, so a 4.0 hook does
142/// not move a rolled-back repository forward again before 3.x is installed.
143pub const REVERSED_MARKER: &str = "greengate-reversed";
144
145/// The name this tool holds a host slot under (`greengate slots`).
146pub const SLOT_HOLDER: &str = "greengate";
147
148/// The label every Job and Workflow of one run carries, read by `collect`
149/// and the batched cluster reads.
150pub const RUN_LABEL: &str = "greengate.run";
151
152/// The annotations naming a cluster Job's gate and tree.
153pub const GATE_ANNOTATION: &str = "greengate.dev/gate";
154pub const TREE_ANNOTATION: &str = "greengate.dev/tree";
155
156// The Kubernetes names below are a contract with homelab's
157// `apps/greengate-gates`, which must define them; only the namespace can be
158// overridden (`greengate.cluster.namespace`). A change to any of them follows
159// the plan's two-change order: homelab adds the new name, then a release.
160
161/// The namespace cluster gates run in, unless `greengate.cluster.namespace`
162/// names another (homelab `apps/greengate-gates`).
163pub const CLUSTER_NAMESPACE: &str = "greengate-gates";
164/// `app.kubernetes.io/managed-by` on every Job and Workflow.
165pub const MANAGED_BY: &str = "greengate";
166/// A cluster Job's name before its slot number.
167pub const JOB_PREFIX: &str = "greengate-gate-slot-";
168/// A detached Workflow's name before its run label.
169pub const WORKFLOW_PREFIX: &str = "greengate-rh-";
170/// The ServiceAccount a detached Workflow's pods run as.
171pub const EXECUTOR_ACCOUNT: &str = "greengate-gate-executor";
172/// The Secret holding the snapshot repository's read token.
173pub const READ_TOKEN_SECRET: &str = "greengate-bot-read-token";
174/// The author and committer name of the commits this tool writes: a cluster
175/// gate's throwaway commit and a detached run's snapshot.
176pub const GIT_AUTHOR: &str = "greengate";
177/// Their email.
178pub const GIT_EMAIL: &str = "greengate@localhost";
179
180/// greengate 3.x's names: what `migrate` moves, and the committed names
181/// (manifest, pack, markers) read until the fleet sweep. Kept here, beside
182/// the new ones, so no module depends on the migration to know them; the
183/// census (Phase 6) removes the read-only ones.
184pub mod old {
185    /// The config namespace.
186    pub const CONFIG_PREFIX: &str = "amont.";
187    /// The environment variables' prefix.
188    pub const ENV_PREFIX: &str = "AMONT_";
189    /// greenpiste's own keys under that namespace: not greengate's to move.
190    pub const FOREIGN_PREFIX: &str = "amont.agent.";
191    /// greenpiste's own environment variables: not greengate's to move.
192    pub const FOREIGN_ENV_PREFIX: &str = "AMONT_AGENT_";
193    /// The held store, never moved (see `migrate`'s module doc).
194    pub const HELD_STORE: &str = "amont-held";
195    /// The held store's index header, which `greengate restore` still reads.
196    pub const HELD_FORMAT: &str = "amont-held-v1";
197    /// The namespace greengate 3.x's homelab cutover ran in.
198    pub const CLUSTER_NAMESPACE: &str = "amont-gates";
199    /// The folder of state greengate 3.x kept in the common dir.
200    pub const STATE_DIR: &str = "amont";
201    /// The committed manifest before 4.0: read when `greengate.conf` is
202    /// absent, until the fleet sweep has renamed every repository's (the
203    /// census removes that read).
204    pub const MANIFEST: &str = "amont.conf";
205    /// A pack repository's file before 4.0. Read whenever `greengate.pack`
206    /// is absent: a vendored pin at an older revision only ever has this one.
207    pub const PACK_FILE: &str = "amont.pack";
208    /// The AGENTS.md markers before 4.0, read until the sweep.
209    pub const AGENTS_START: &str = "<!-- amont:start -->";
210    pub const AGENTS_END: &str = "<!-- amont:end -->";
211}
212
213#[cfg(test)]
214mod tests {
215    use super::*;
216
217    #[test]
218    fn the_macros_and_the_constants_agree() {
219        assert_eq!(BIN, PRODUCT);
220        assert_eq!(FLEET_BIN, concat!(bin!(), "-fleet"));
221        assert_eq!(CRATE, BIN);
222        assert!(NPM_PACKAGE.ends_with(BIN));
223        assert!(BREW_FORMULA.ends_with(BIN));
224        assert!(INSTALLER_URL.contains(REPO));
225    }
226}