Skip to content
Myr

Give back only checked data from visibility(), and test that every stated value beats its default

Before adoption: this commit came in with the history the project adopted, so no landing records it.

- visibility() returned the held-back checks object as the file passed it, so a key the schema doesn't name (a check's paths, or a function) reached the policy. It now returns the checked suite, re-attaching only the areas as written (checked with the rest) so AreaOf keeps their names. - New test: a suite stated with a paths key comes back without it (red by assertion before the fix). - New test: every value stated off its default (attempts, admit, layer, env setters, release, audience, readers, writers, notice, maxDays, two kinds' sunsets) comes through, and canary defaults to false. The OSR tests passed values equal to the defaults, so a builder that ignored them stayed green; seen red against planted perClaim: 3, a fixed release and Math.max for the sunset. - layer()'s sunset doc says the layer takes the soonest (the protocol keeps one sunsetDays); the sdk and CLI entry headers name visibility.ts and a layer's layer.ts, reflowed.

authored by oscabriel · committed by oscabriel · parent 319f845 · Browse files · 4 files+115 added−14 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+115 added−14 removed

  • tests:+94 added−0 removed
  • other:+21 added−14 removed

4 files+115 added−14 removed

modified:apps/cli/src/entries/rules.ts+4 added-3 removed
modified:packages/sdk/src/index.ts+5 added-4 removed
modified:packages/sdk/src/visibility.ts+12 added-7 removed
55 unmodified lines
56 /** Who may clone it. */57 readonly readers?: MembersInput;58 /** Why it exists, in public. */59 readonly reason: string;60 /** How long each kind it holds may stay unreleased: `{ experiment: "30 days" }`. */60 /**61 * How long each kind it holds may stay unreleased: `{ experiment: "30 days" }`.62 * The protocol keeps one sunset a layer, so the layer takes the soonest.63 */64 readonly sunset?: Readonly<Partial<Record<Holds[number], Days>>>;65 /** Who may push to it. */66 readonly writers?: MembersInput;67}
191 unmodified lines
259 narrowingDays: Duration.toDays(config.notice?.narrowing ?? "7 days"),260 },261 };262260 // Checked whole, then the held-back checks given back as stated, so261 // their areas keep the names `AreaOf` reads.262 const stated = Struct.omit(263 policyOf(checks === undefined ? policy : { ...policy, checks }),264 ["checks"]263 // Checked whole, so a key the schema doesn't name (a check's path) is264 // dropped. The held-back checks' areas, checked with the rest, come back265 // as the file wrote them, so they keep the names `AreaOf` reads.266 const { checks: suite, ...stated } = policyOf(267 checks === undefined ? policy : { ...policy, checks }268 );269267 return checks === undefined ? stated : { ...stated, checks };270 return checks === undefined || suite === undefined271 ? stated272 : { ...stated, checks: { ...suite, areas: checks.areas } };273};274275/**276 * The areas a visibility file's (or a `sealedChecks`'s) held-back checks
37 unmodified lines
modified:packages/sdk/test/visibility.test.ts+94 added
143 unmodified lines
144145 expect(definition).toStrictEqual(osrPolicy);146 });147148 it("keeps every value the file states over its default", () => {149 const definition = visibility({150 checks: sealedChecks({151 admit: { greenOnMainRuns: 5, redOnKnownBadAtLeast: 2 },152 areas: { parser: "src/parser/**" },153 attempts: { perClaim: 2, perPersonPerAreaPerWeek: 6 },154 layer: "evidence",155 }),156 env: { setters: ["alice"] },157 flows: flows.noWriteDown({ release: ["bob"] }),158 layers: {159 evidence: layer({160 audience: "team",161 disclose: "declared",162 holds: ["checks", "experiment", "notes"],163 readers: ["alice", "carol"],164 reason: "The team's checks, experiments and notes",165 sunset: { experiment: "2 weeks", notes: "90 days" },166 writers: ["alice"],167 }),168 security: embargo({169 disclose: "counted",170 maxDays: 30,171 readers: ["dave"],172 }),173 },174 notice: { narrowing: "2 weeks" },175 });176177 const expected = {178 checks: {179 admit: { greenOnMainRuns: 5, redOnKnownBadAtLeast: 2 },180 areas: { parser: "src/parser/**" },181 attempts: { perClaim: 2, perPersonPerAreaPerWeek: 6 },182 canary: false,183 commit: "salted-sha256-merkle",184 layer: "evidence",185 pin: "claim",186 result: "area-bit",187 },188 env: { setters: ["alice"] },189 flows: { noWriteDown: true, release: ["bob"] },190 layers: [191 {192 audience: "team",193 disclose: "declared",194 holds: ["checks", "experiment", "notes"],195 name: "evidence",196 readers: ["alice", "carol"],197 reason: "The team's checks, experiments and notes",198 // The protocol keeps one sunset a layer: the soonest stated.199 sunsetDays: 14,200 writers: ["alice"],201 },202 {203 audience: "security",204 disclose: "counted",205 holds: ["fix"],206 maxDays: 30,207 name: "security",208 readers: ["dave"],209 reason: "Embargoed fixes, released with their advisory",210 writers: "deciders",211 },212 ],213 notice: { narrowingDays: 14 },214 };215216 expect(definition).toStrictEqual(expected);217 expect(decodePolicy(definition)).toStrictEqual(expected);218 });219220 it("gives back only what the policy names: a check path stated beside the areas never reaches it", () => {221 const stated = {222 ...sealedChecks({ areas: { export: "src/export/**" } }),223 paths: ["checks/export/escapes-titles.test.ts"],224 };225226 const definition = visibility({227 checks: stated,228 layers: {229 maintainers: layer({230 disclose: "sealed",231 holds: ["checks"],232 reason: "Held-back checks for export",233 }),234 },235 });236237 expect(definition.checks).toStrictEqual(238 sealedChecks({ areas: { export: "src/export/**" } })239 );240 });241242 it("declares an embargo and the personal layer as config alone: no repo, no held-back checks", () => {243 const definition = visibility({244 layers: {245 personal: personal(),
158 unmodified lines