Add the Software Factory configuration YAML model
What does this MR do and why?
This adds the boring, tedious part of the software factory configurator. It's all the bits that allow you to write, edit, and re-write your config in the UI without borking everything. That's why the overwhelming majority of this MR is test cases. We want to be sure that all the weird and wonderful ways that you can save a valid YAML file won't break the editor, and and changes you make to those files using the editor, won't remove anything (valid) that you added outside the editor.
This is difficult to explain, so here's a scenario:
- You use the UI to create a
.gitlab-dap-factory.ymlfile. It should save as a valid file with correct formatting. - You edit that YAML file in your own IDE. You use different formatting, you add comments, you do all the things that YAML lets you do that the editor would never do. It's a mess, but it's valid.
- Your open that franken-config in the factory config UI. Everything renders as expected.
- You make changes to that config in the UI and save it. Everything saves as valid YAML. Your comments are preserved, your weird quirks remain if they're structural, but it's formatted in a nicer way.
- The software factory continues on unimpeded.
Nothing uses any of this yet. The page that assembles it, and the four presentational components it sits beside, follow in later merge requests. No GraphQL, no Apollo, no queries here.
Note: The config shape itself is still in flux. Which, unfortunately, means all this code is likely to be thrown away. It also means that we don't need to comment on the structure of the YML here. As long as it matches what we expect, we're golden. It's almost deliberatly bad config design at this point.
What the round trip preserves, and the five things it cannot
Preserved across an edit: comment text and position, including comments on their own line, single-space inline comments, and the comment on an empty block the editor fills; key order; unknown keys; indentation width, measured from the blocks rather than guessed from the first indented line; CRLF line endings; long unwrapped scalars; quote styles; anchors and aliases outside the blocks the editor writes; and sequences.
Not preserved, all whitespace-only:
| A run of two or more blank lines | collapses to one |
| Padding that aligns an inline comment | collapses to a single space, everywhere in the file |
Flow collection padding, [a, b] |
becomes [ a, b ], everywhere in the file |
| A plain scalar the author wrapped by hand | joined onto one line |
| A sequence written in its parent's column | indented under its key |
The parser records none of that whitespace, so no edit can put it back. All of it can reach lines the edit never touched, so "only the edited line changes" holds for a factory config written without these shapes, and not otherwise. Every one is pinned by a spec under round trip > whitespace it cannot keep. Nothing structural moves in any of them.
Two smaller notes. A block scalar body is written at the indent of the file, so a body indented differently moves — bounded to the body itself. The comment on an empty block is kept but lands one line lower, above the first key the editor writes, which is stable on the next edit.
Found by sweeping a no-op edit across 400 YAML files in config/, .gitlab/ and doc/.vale/: beyond the rows above, every file was either byte-identical or correctly refused.
References
- Task: https://gitlab.com/gitlab-org/gitlab/-/work_items/637194
- Parent issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/637188
- Proof of concept: !264560 (closed)
- Builds on: !264937 (closed)
Screenshots or screen recordings
No UI in this merge request. It adds two modules and their specs; nothing renders and nothing is wired into a page.
How to set up and validate locally
Nothing renders, so there is no page to visit. The claim worth checking by hand is the one the specs can only make against files I chose: edit one field, and the rest of your file comes back untouched.
Point this at any YAML file. It parses and re-stringifies with the options this merge request adds, then diffs the result against the original. No output means the file survived.
node -e '
const { readFileSync } = require("fs");
const { parseDocument } = require("yaml");
const s = readFileSync(process.argv[1], "utf8");
const out = parseDocument(s).toString({
indent: /^( +)\S/m.exec(s)?.[1].length ?? 2,
lineWidth: 0,
});
process.stdout.write(s.includes("\r\n") ? out.replace(/\n/g, "\r\n") : out);
' your-factory.yml | diff your-factory.yml -That is the same yaml call and the same options stringify() makes, CRLF handling included. It needs no build and no GitLab code, so it checks the part that is hard to believe. What the module does with those options is what the 62 specs are for.
What you should see
A factory config, with the options this merge request adds — nothing. It survived:
The same file with the options removed (.toString() with no arguments). This is the bug:
5,7c5,7
< triage: Start
< build: In dev
< ship: Done
---
> triage: Start
> build: In dev
> ship: Done
10,12c10,12
< build:
< start: automated
< flow: 414
---
> build:
> start: automated
> flow: 414Six lines re-indented on a twelve-line file, none of them edited. On this repository's own .gitlab-ci.yml, the defaults change 532 of 541 lines; the options bring that to 20.
A file with aligned inline comments, with the options. This is the known limitation below, not a regression:
2,3c2,3
< triage: Start # aligned
< build: In dev # aligned
---
> triage: Start # aligned
> build: In dev # alignedMR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
- Tests: 62 Jest examples across the two new modules. RSpec was not run — this worktree is outside the GDK, so Rails does not boot. There are no Ruby changes in this merge request, so CI is the gate for anything beyond Jest.
- Changelog: not needed. The feature sits behind the default-off
dap_software_factoryflag, and nothing in this merge request is reachable by a user. - Documentation: not needed. This is an experiment, the step after a proof of concept, and the model will change again before any of it is worth documenting.
- Database / Application Security review: not needed. No migrations, no queries, no authentication or authorization paths.
- Translation: three new strings, all externalized with
s__and extracted intolocale/gitlab.pot.