Skip to content
Myr

Merge build/standing-caps into main

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

authored by oscabriel · committed by oscabriel · parents 05cecd1, a94a941 · Browse files · 6 files+47 added−11 removed
This commit

State

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

Diff stats

6 files+47 added−11 removed

  • tests:+26 added−3 removed
  • other:+21 added−8 removed

6 files+47 added−11 removed

modified:packages/project/src/attention/proposals.ts+3 added-2 removed
25 unmodified lines
26import { ProjectEventInput } from "../events.ts";27import { AttentionEffect } from "./effects.ts";2829interface Proposer {30 readonly capped: boolean;31 readonly denounced: boolean;32 readonly id: ProposalId;33 readonly openCount: number;34 readonly project: ProjectName;
43 unmodified lines
78};7980const admit = (81 policy: Policy,81 { denounced, openCount }: Proposer,82 { capped, denounced, openCount }: Proposer,83 unvouched: boolean84): Result.Result<void, CapReached | Denounced | NotVouched> => {85 const cap = policy.caps.proposalsPerPerson;86
4 unmodified lines
91 if (unvouched) {92 return Result.fail(new NotVouched({}));93 }9494 return openCount >= cap95 return capped && openCount >= cap96 ? Result.fail(new CapReached({ cap, limit: "proposals" }))97 : Result.void;98};99
215 unmodified lines
modified:packages/project/src/attention/vouch.ts+7 added
modified:packages/project/src/deciders.ts+3 added-1 removed
98 unmodified lines
99} from "./attention/proposals.ts";100import type { Proposed } from "./attention/proposals.ts";101import { recordOf } from "./attention/record.ts";102import { today } from "./attention/today.ts";103import { standing } from "./attention/vouch.ts";103import { capped, standing } from "./attention/vouch.ts";104import { ClaimState } from "./claim.ts";105import { DraftResult } from "./draft-runs.ts";106import type { UnlandedRunEnv } from "./env-port.ts";107import { ProjectEventInput } from "./events.ts";
898 unmodified lines
1006 const proposed = yield* Effect.fromResult(1007 propose(1008 policy,1009 ProposalCommand.Propose({1010 capped: capped(who),1011 denounced: who === "denounced",1012 files: files.map(({ path }) => path),1013 id: ProposalId.make(1014 minted("prop", proposalsNow(h, writes).length)
65 unmodified lines
1080 propose(1081 policy,1082 ProposalCommand.Flag({1083 ask: input.ask,1084 capped: capped(standing(policy, [], caller.handle)),1085 denounced: standing(policy, [], caller.handle) === "denounced",1086 id: ProposalId.make(1087 minted("prop", proposalsNow(h, writes).length)1088 ),
1092 unmodified lines
modified:packages/project/src/project.ts+8 added-5 removed
190 unmodified lines
191import type { AnswerQueue, AnswerRuns, RunnableEffect } from "./answer-runs.ts";192import { isStep } from "./answer-runs/steps.ts";193import { openDecision } from "./attention/decisions.ts";194import { recordOf } from "./attention/record.ts";195import { mayClaim, standing } from "./attention/vouch.ts";195import { capFor, capped, mayClaim, standing } from "./attention/vouch.ts";196import {197 ClaimCommand,198 ClaimEffect,199 ClaimState,
4043 unmodified lines
42434244 return {4245 denounced: who === "denounced",4246 race: kind?.race ?? 1,4247 standing: who,4248 vouched: admitted,4249 };4250 };4251
22 unmodified lines
42744275 const command = ClaimCommand.cases.Claim.make({4276 base: live.value.landed,4277 blockedBy: remainingBlockers(ask.value, h.asks),4277 cap: policy.caps.claimsPerPerson,4278 cap: capFor(trust.standing, policy.caps.claimsPerPerson),4279 denounced: trust.denounced,4280 heldByWho: heldBy(h, caller.handle, id),4281 liveCount: h.claims.filter(4282 ({ row, state }) =>
216 unmodified lines
4499 pushFacts({4500 ask,4501 base,4502 claim: view,4503 claimsHeld:4504 Principal.guards.Person(input.pusher) &&4502 claimsHeld: Principal.guards.Person(input.pusher)4503 ? heldBy(h, input.pusher.handle)4504 : 0,4505 capped(standing(h.policy.value, [], input.pusher.handle))4506 ? heldBy(h, input.pusher.handle)4507 : 0,4508 head: input.after,4509 landed: live.value.landed,4510 policy: h.policy.value,4511 project: name,
861 unmodified lines
modified:packages/project/test/attention/proposals.test.ts+8 added
40 unmodified lines
41const byCarol = (42 standing: Partial<Parameters<typeof ProposalCommand.Propose>[0]> = {}43) =>44 ProposalCommand.Propose({45 capped: true,46 denounced: false,47 files: [RepoPath.make("packages/parser/test/iso-week.test.ts")],48 id: minted.proposal(),49 openCount: 0,
11 unmodified lines
61 standing: Partial<Parameters<typeof ProposalCommand.Flag>[0]> = {}62) =>63 ProposalCommand.Flag({64 ask: flagged,65 capped: true,66 denounced: false,67 id: minted.proposal(),68 openCount: 0,69 project: scenario.project,
41 unmodified lines
111 Result.fail(new CapReached({ cap: 2, limit: "proposals" }))112 );113 });114115 it("lets a vouched person propose past the cap, which is for the public", () => {116 expect(117 Result.isSuccess(proposalOf(byCarol({ capped: false, openCount: 20 })))118 ).toBeTruthy();119 });120121 it("lets a person with one fewer than the cap open propose", () => {122 expect(123 Result.map(proposalOf(byCarol({ openCount: 1 })), ({ state }) => state)124 ).toStrictEqual(Result.succeed("open"));
154 unmodified lines
modified:packages/project/test/deciders.test.ts+18 added-3 removed
301 unmodified lines
302303 const onToday = yield* api.today(alice);304 const alarm = yield* scheduled;305306 // The cap is for the public: dave is not vouched, carol is.306 const second = yield* api.proposeAsk(carol, { want: "Trim tabs too" });307 const second = yield* api.proposeAsk(dave, { want: "Trim tabs too" });308309 yield* api.proposeAsk(dave, { want: "Trim spaces too" });310311 const third = yield* api309 .proposeAsk(carol, { want: "Trim newlines too" })312 .proposeAsk(dave, { want: "Trim newlines too" })313 .pipe(Effect.flip);314315 const beyondCap = yield* api316 .proposeAsk(carol, { want: "Trim carriage returns too" })317 .pipe(Effect.result, Effect.map(Result.isSuccess));318319 yield* redOnMain(files);320321 const accepted = yield* api.decide(alice, {322 choice: "accept",
7 unmodified lines
330 again: yield* api331 .decide(alice, { choice: "decline", decision: firstDecision })332 .pipe(Effect.flip),333 alarm,334 beyondCap,335 bobDecides: yield* api336 .decide(bob, {337 choice: "accept",338 decision: DecisionId.make("dec-000002"),
134 unmodified lines
473 subject: DecisionSubject.cases.OpenProposal.make({ proposal }),474 },475 ]);476 expect(run.alarm).toStrictEqual(Option.some(daysAfter(noon, 14)));469 expect([run.second.proposal.state, run.third]).toStrictEqual([477 expect([478 run.second.proposal.state,479 run.third,480 run.beyondCap,481 ]).toStrictEqual([482 "open",483 new CapReached({ cap: 2, limit: "proposals" }),484 true,485 ]);486 })487 );488
26 unmodified lines
515 expect(run.proposals.map(({ id, state }) => [id, state])).toStrictEqual(516 [517 [proposal, "accepted"],518 [ProposalId.make("prop-000002"), "open"],519 [ProposalId.make("prop-000003"), "open"],520 [ProposalId.make("prop-000004"), "open"],521 ]522 );523 })524 );
983 unmodified lines