mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
Type size, density and accent were kept in localStorage, which is per-origin, so hanzo.ai, hanzo.chat, hanzo.app and console held four independent copies of one person's setting. Measured: text set to 1.3 on hanzo.ai rendered 18.2px there and 14px on the other three, same browser, same person. A setting that does not travel reads as a setting that does not work. It nests in the hanzo.preferences blob beside consent -- no second key, no second table -- with per-application overrides resolved axis by axis, so an app can differ on density without restating a type scale. Every axis's zero value means "not set", and that is load-bearing: 0 for the type scale sits outside 0.85..1.4, so "never chose" stays distinct from "chose the middle setting". The read half and Validate share one definition of what an axis accepts, because a value they disagreed about would be stored and never shown. Consent's merge helpers were hardcoded to its own key, so appearance would have needed a second identical merge -- the one thing the ConsentKey comment forbids. They are one now, parameterized by key, and consent is 62 lines lighter for it. The OIDC preferences endpoint shallow-merges opaque JSON, so it runs a patch through the parser: without that the validation is decorative, and a client could store a density nothing renders while the person is told it saved. Co-authored-by: Hanzo Dev <[email protected]>
51 lines
1.8 KiB
Go
51 lines
1.8 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package oidc
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hanzoai/iam/pkg/schema"
|
|
)
|
|
|
|
// The preferences surface is where a person's appearance is written, and it
|
|
// merges whatever top-level keys a client sends. A choice this version cannot
|
|
// render has to be refused HERE: stored, it is dropped again by every reader, and
|
|
// the person is told a setting saved that no screen ever shows.
|
|
func TestPreferencesRefusesAnUnrenderableAppearance(t *testing.T) {
|
|
for _, patch := range []string{
|
|
`{"appearance":{"density":"cosy"}}`,
|
|
`{"appearance":{"type":4}}`,
|
|
`{"appearance":{"type":0.1}}`,
|
|
`{"appearance":{"accent":"red;} html{display:none}"}}`,
|
|
`{"appearance":{"apps":{"console":{"density":"roomy"}}}}`,
|
|
`{"appearance":"compact"}`,
|
|
`{"theme":"dark","appearance":{"density":"cosy"}}`,
|
|
} {
|
|
t.Run(patch, func(t *testing.T) {
|
|
if _, _, err := mergePreferences(`{"appearance":{"density":"compact"}}`, []byte(patch)); err == nil {
|
|
t.Fatalf("the preferences surface accepted an unrenderable appearance: %s", patch)
|
|
}
|
|
})
|
|
}
|
|
|
|
// And a real one still merges, alongside every other preference.
|
|
merged, m, err := mergePreferences(
|
|
`{"theme":"dark","consent":{"insights":true,"training":"granted"}}`,
|
|
[]byte(`{"appearance":{"type":1.25,"density":"comfortable","accent":"#ff6600"}}`),
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("a real appearance was refused: %v", err)
|
|
}
|
|
if got := string(m["theme"]); got != `"dark"` {
|
|
t.Fatalf("theme = %s, want \"dark\"", got)
|
|
}
|
|
if got := schema.AppearanceOf(merged).For("console"); got != (schema.Style{Type: 1.25, Density: schema.DensityComfortable, Accent: "#ff6600"}) {
|
|
t.Fatalf("the saved appearance reads back as %+v", got)
|
|
}
|
|
if !schema.ConsentOf(merged).MayTrain() {
|
|
t.Fatalf("an appearance write altered the stored consent: %s", merged)
|
|
}
|
|
}
|