Skip to content

Test machine-media.mjs, and fix a hostname that could end in a hyphen - #9

Merged
MyOwnDataCenter merged 2 commits into
MyOwnDataCenter:mainfrom
nixfred:test/machine-media
Nov 14, 2026
Merged

MyOwnDataCenter merged 2 commits into
MyOwnDataCenter:mainfrom
nixfred:test/machine-media

Conversation

@nixfred

@nixfred nixfred commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

What this changes

Adds tests for omarchyd/machine-media.mjs, the module that builds what a new machine installs itself from (cloud-init, the Omarchy ISO's disk layout, the Windows answer file). It was the one module issue #6 was kept open for.

They found one bug, fixed in the second commit: a machine name can be 64 characters, and hostnameFor cut the cleaned name to 63 characters after it had already trimmed hyphens, so <62 letters> b became <62 letters>-, which is not a valid hostname. The cut now happens first, then trailing hyphens are trimmed.

How you tested it

  • npm run typecheck, npm run build and npm test pass (133 tests, 9 of them new)
  • Not tried on a real Omarchy machine or VM. The new tests only call pure functions; the one code change is in hostnameFor, which names new machines, and I have not created a machine with a 64-character name.

Anything to know

  • Two commits: the tests, then the fix. The fix's test case fails on main ('aaaa…a-' instead of 'aaaa…a') and passes with it.
  • Noticed and left alone: cloudUserData checks that packages is a list but not commands, so a catalog entry with commands: "x" would throw. Only the repo's own catalog file can do that, so I did not change it here.
  • Version number and What's New left alone, as CONTRIBUTING asks.

Closes #6

🤖 Generated with Claude Code

https://claude.ai/code/session_01BXN1v3McRXvDta1mtsKJkR

nixfred and others added 2 commits November 14, 2026 13:09
…answer file

omarchyd/machine-media.mjs builds what a new machine installs itself from, and
had only one partial test inside machines.test.mjs. test/machine-media.test.mjs
covers every export:

- hostnameFor: cleaning, the 63 character limit and the machine-<id> fallback.
- PUBLIC_KEY and cloudUserData: only public keys get in (a private key, a quote
  in the comment and a second line are refused), groups, shell, the password
  line and the chpasswd block, and package names and commands from the catalog
  checked before they are written.
- cloudMetaData: a new instance id every time.
- omarchyConfiguration and omarchyCredentials: one disk, the boot partition,
  the Btrfs subvolumes and room left at the end of the disk.
- isWindowsLabel and isWindowsClientLabel.
- windowsAnswerFile: computer name cleaned and cut to 15 characters, XML
  escaping of the user name and product key, and a password that decodes back
  to UTF-16LE(password + "Password") even with accents, never in plain text.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BXN1v3McRXvDta1mtsKJkR
A machine's name can be up to 64 characters. hostnameFor cut the cleaned name
to 63 characters after it had already trimmed hyphens from the ends, so a
name like "<62 letters> b" became "<62 letters>-", which is not a valid hostname
(a hostname cannot end in a hyphen). The cut now happens first, then trailing
hyphens are trimmed again.

Found by the new tests in test/machine-media.test.mjs. I have not checked what
cloud-init does with such a name; the fix just keeps it valid.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BXN1v3McRXvDta1mtsKJkR
@MyOwnDataCenter
MyOwnDataCenter merged commit ce07dd9 into MyOwnDataCenter:main Nov 14, 2026

Copy link
Copy Markdown
Owner

Thank you, this is excellent work: careful tests, and a real bug found and fixed. Splitting the tests and the fix into two commits made it easy to verify.

Accepted and merged. What I checked:

  • The bug: on the old code, a 64-character name like <62 letters> b really does give a 63-character hostname ending in -. With your fix it gives a valid 62-character one.
  • Ordinary names: they come out exactly as before (Ubuntu Desktop → ubuntu-desktop; --- and é → machine-<id>).
  • The checks: with this branch on top of main, the type check, build and full suite (133 tests) all pass.

This finishes #6. Good spot on commands in cloudUserData as well; I'll take care of that separately.


Generated by Claude Code

MyOwnDataCenter pushed a commit that referenced this pull request Nov 14, 2026
- omarchyd used <data>/tls while the web server used ~/.local/share/
  omarchy-server/tls, so app gateways served a certificate from a different
  authority than the one devices trust, and Security settings (always https,
  replace certificate) only reached omarchyd. omarchyd/cli.mjs now passes
  defaultTlsDir(); an "always https" choice from the old folder is carried over.
- omarchyd/prompt.mjs: the create-owner prompt reads input character by
  character, so a pasted password with its Enter (or both passwords at once)
  works (reported by nixfred in #10).
- cloudUserData ignores a non-list `commands` (noted by nixfred in #9).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011b9fuB8ePE7DYtvvqNj1s2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for files, tls, system and machine-media

2 participants