feat(ui): instance label and color global settings with deployment defaults [IFC-3232, IFC-3588]
Summary
Teams that run several Infrahub instances (development, QA, production, or one per region) cannot tell from the web UI which instance a tab shows. This PR adds an instance label and an instance color. An administrator who holds manage_global_preferences saves them on the Global preferences page, and an operator can set a default for each one per deployment with INFRAHUB_INSTANCE_LABEL and INFRAHUB_INSTANCE_COLOR. A saved value overrides the deployment default. A change saved in the UI applies without a restart.
Every visitor, including on the login page, then views:
- a badge with the label at the right of the top header, next to the task and repository status indicators, and above the logo on the login page;
- a 3 px bar in the instance color across the top of the page;
- a browser tab title of the form
<label> · <page title>; - the Infrahub logo in the instance color as the tab icon.
Sources:
- Jira: IFC-3232 (delivery of INFP-538, mirrored from opsmill/infrahub#10690) and IFC-3588 (deployment defaults and tab icon, included in this PR).
- Spec, plan and tasks:
dev/specs/007-instance-badge-ifc-3232/.
Screenshots
Backend changes
- Two nullable fields,
instance_labelandinstance_color, on the globalPreferencerow (owner_id = "__global__"). No schema node, no migration, no seeded row. InfrahubSetPreferences(scope: GLOBAL)acceptsinstance_label: Stringandinstance_color: InstanceColor. An omitted argument leaves the value unchanged andnullresets it. Withscope: USERboth arguments are rejected before any read.- Label rules, shared by the mutation and the deployment default: the label is trimmed, an empty label resets, and a label over 32 code points, or with a control character, a Unicode line or paragraph separator, or a bidirectional control, is rejected. The label
NULLis rejected too, because preference nodes store an unset property as that text, so it would read back as unset. The rules and theInstanceColorenum are inbackend/infrahub/instance_identity.py, so thatconfig.pycan import them without importinginfrahub.core. InstanceColorhas name == value (RED,AMBER,GREEN,BLUE,INDIGO,PURPLE,GRAY), so the GraphQL enum names and the REST values are the same.InfrahubGlobalPreferencesreturns both saved fields through a newGlobalPreferencesType. The user and effective preference types do not expose them. The query returns the saved values only, never the deployment default.- A stored color is read strictly, the same way as
date_format. - New
InstanceSettings(INFRAHUB_INSTANCE_LABEL,INFRAHUB_INSTANCE_COLOR, or the[instance]section ofinfrahub.toml). An empty value counts as not set, and the color is accepted in uppercase or lowercase. An invalid label or color stops Infrahub at startup with an error that names the environment variable, for exampleINFRAHUB_INSTANCE_COLOR must be one of RED, AMBER, GREEN, BLUE, INDIGO, PURPLE, GRAY. GET /api/config(public) gains two objects:instance: { label, color }: each field is the saved value, else the deployment default, elsenull. Reading never creates the preference row. When the read of the saved values fails, the endpoint servesnullfor both fields so that the login page still loads. It does not serve the deployment defaults in that case, because a default can name another stage than the saved value it would replace.instance_defaults: { label, color }: the deployment defaults,nullwhen not set.
- Both compose files declare the two variables.
tasks/docs.pynow renders an optional enum setting in the configuration reference.
Frontend changes
InstanceBadge: a tintedBadgevariant per color (newindigovariant), truncated atmax-w-48with a tooltip that shows the full label.InstanceColorBar: 3 px, above the sidebar and the header, and at the top of the login page. Nothing renders and no space is reserved when no color is set.- Document title:
useTitleregisters the page title in an atom, and a singleDocumentTitlecomponent writes<label> · <page title>, or<label> · Infrahubwhen the page has no title. This fixes the child-first effect order that let the layout overwrite the page title on a hard load. InstanceFavicon: when a color is in effect, it replaces the accent and outline colors ofinfrahub-mark.svgwith the preset color (the light-mode shade of the color bar) and sets the result as the tab icon. It restores the original icon when the color is reset.- Instance identity card on the Global preferences page:
- a label input with a code-point counter and validation while typing;
- a color combobox with a swatch per preset;
- when a deployment default exists, the label placeholder shows it with the helper text
Leave empty to use the deployment default: <label>., and the color picker showsDeployment default: <color>; - the save button is named "Save instance identity", so the existing "Save" locators stay unique;
- only changed fields are sent, so two administrators who edit different fields do not overwrite each other; a saved color that this frontend build does not know counts as unchanged, so a label-only save keeps it.
ComboboxItemgains an optionalicon, rendered in the list and on the closed trigger.ConfigProvidershows the error screen only when no config was ever loaded. Before, a failed refetch of/api/config(on tab focus, and now after an identity save, withretry: false) replaced the whole app with the error screen while the old config was still loaded. Separate changelog fragment:+config-refetch-error-screen.fixed.md.
Documentation
docs/docs/deploy-manage/user-management/managing-preferences.mdx: the instance label and color section (web and GraphQL tabs), the deployment defaults and their order of resolution, and the/api/configresponse.docs/docs/reference/configuration.mdx: regenerated with the[instance]section.dev/knowledge/backend/preferences.md,dev/knowledge/frontend/shared-components.md, and one changelog fragment (+ifc-3232-instance-badge.added.md) for both tickets.
Design decisions
- Four badge directions were prototyped in a design jam: badge left in the header, badge right with a solid fill, a banner strip with the label, and a badge under the sidebar logo. The tinted badge of the first direction was kept, at the right of the header as the tech owner asked. The prototype route was deleted before this PR, and its record is not kept in the repository.
- The deployment defaults stay editable in the UI: a saved value overrides the default, and resetting the saved value applies the default again. The tech owner chose this over locking the fields when an environment variable is set.
- The tab icon reuses the Infrahub logo instead of a generic colored shape, so that the tab stays recognizable as Infrahub.
Tests
- Backend:
- unit tests for the label rules (whitespace reset, over-long, control characters,
NULL) and forInstanceSettings(environment variables, empty values, invalid label or color); - component tests for the repository (both fields read back as
Noneon a row saved without them); the mutation (sets both, one field alone, omitted vs null, trim, unknown color rejected with nothing stored, USER scope rejected with no USER row, an account without the permission cannot write the label or the color and the stored values are unchanged); the global and user queries; and/api/config(anonymous read, no row created, saved values, per-field fall back to the deployment defaults, the defaults served again after a reset). A unit test with a failing repository checks that a failed read serves no identity but still servesinstance_defaults.
- unit tests for the label rules (whitespace reset, over-long, control characters,
- Frontend: rules (title composition, color map, label rule, logo recoloring), the config refresh after a save,
ConfigProvideron a failed refetch,useTitleandDocumentTitle, badge, bar, tab icon, header order, layout, login page, the identity form (per-field payloads, validation, deployment default placeholders) and the combobox icon. - E2E:
tests/e2e/preferences/test_instance_identity.pycovers the saved values (admin sets them; a read-only user views the badge, the bar and the tab title, also after a reload; the anonymous login page; clearing the label keeps the bar; nothing set renders nothing). The deployment defaults have no E2E test, because the suite starts one server for the whole session and cannot set its environment per test.
Known limitations and open points
- While a deployment sets a default, the web interface can replace that label or color but cannot remove it. To show no label or no color, remove the environment variable and restart Infrahub. This follows the chosen order: saved value, else deployment default.
- Safari support for an SVG data URL as the tab icon has not been checked.
- The resolution of saved value over default is done in
InstanceIdentityResolverinbackend/infrahub/api/internal.py, which only/api/configuses. No other consumer of the instance identity exists today. /api/confignow reads the database on each call, with no time limit. A stalled database keeps every page, the login page included, on the loading screen until the read answers. A failed read is handled; a slow one is not.
Review
Reviewed with the reviewing-code skill (bugs, approach, rules, design, cleanup, architecture, specs and claims), then a second round on the fixes, then a third full round. Fixed:
- Docs said to select No color to reset the color; that option does not exist. The color is reset by selecting the current color again.
- A failed save showed the same error toast twice, in both global preference forms.
- A save of the date and time defaults also refetched
/api/config. It now refetches it only when the label or the color was sent. - A test patched a repository method; it now injects a failing repository. One test checked an error by substring; it now checks the exact message. Duplicate tests were removed.
- Specs, knowledge notes and this description had stale names and claims. The two changelog fragments are merged into one.
- Third round: the label
NULLread back as unset; a label-only save from older frontend code erased a color it did not know; a failed config refetch replaced the whole app; no test covered a write of the instance fields without the permission; duplicate tests; the color descriptions now name the tab icon; docs, spec and the backpressure note (/api/confignow reads the database) corrected.
Declined:
- "One admin's save can revert another's label": the shared
Formresets to the refetched values (frontend/app/src/shared/components/ui/form.tsx:55), so the comparison is already against the current values. A test written for the proposed fix showed it sent the other admin's label, so it was not applied. - Moving the "saved, else default" rule into
core/: the reviewer asked for the current resolver shape. - Frontend style rules (React import style,
Row/Col): those rules are not ondevelopyet. - A read-only database session for
/api/config: applied, then reverted, because on a Neo4j cluster a read routed to a follower can return the old values right after a save. - Storing an unset preference as a real null instead of the text
NULL: it changes how everyStandardNodeproperty is stored, outside this PR.
Gates
Run on the pushed head with /pre-ci:
- Python:
main.lint, repo-wide ruff check and format check,ty, mypy, lockfiles, yamllint, the huge-runner gate, generated files, GraphQL and JSON schema validation: all passed. - Backend unit tests: 5238 passed. The 2 failures (
test_remote_refs.py,writeback/test_git_adapter.py) are git tests that expect wording the authoring machine's git version does not print; neither file is in this diff. - Frontend:
biome ci,knip,betterer(168, unchanged), OpenAPI and GraphQL types: passed. Unit tests: 387 of 388 files passed; the one failure isfetch.test.ts, caused by a local-only API URL change on the authoring machine (it passes with the committed config).@infrahub/graph: 23 passed. - Docs: markdownlint 0 issues;
docs.validateclean. Vale is not installed on the authoring machine. - E2E: not run locally; CI runs it.