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
Provenance
- Commit
8a78de8- Tree
8a33b8c- Author
oscabriel <oscarhernandeziv@gmail.com>- Committer
oscabriel <oscarhernandeziv@gmail.com>- Parent 1
05cecd1- Parent 2
a94a941
6 files changed+47 added−11 removed
modified:packages/project/src/attention/proposals.ts+3 added-2 removed
25 unmodified lines26 import { ProjectEventInput } from "../events.ts";27 import { AttentionEffect } from "./effects.ts";28 29 interface Proposer {30+ readonly capped: boolean;31 readonly denounced: boolean;32 readonly id: ProposalId;33 readonly openCount: number;34 readonly project: ProjectName;43 unmodified lines78 };79 80 const 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 lines91 if (unvouched) {92 return Result.fail(new NotVouched({}));93 }94 94- return openCount >= cap95+ return capped && openCount >= cap96 ? Result.fail(new CapReached({ cap, limit: "proposals" }))97 : Result.void;98 };99 215 unmodified linesmodified:packages/project/src/attention/vouch.ts+7 added
84 unmodified lines85868788899091929394959697989951 unmodified lines84 unmodified lines ), });};
/** The caps are for the public: someone the project vouches for, or a decider, works without them. */export const capped = (who: Standing) => who !== "vouched";
/** What a person may hold of a capped thing at once; no limit for a vouched one. */export const capFor = (who: Standing, cap: number) => capped(who) ? cap : Number.MAX_SAFE_INTEGER;
const mentored = ({ ask, landingsInProject }: ClaimQuestion) => ask.reserve === "newcomers" && ask.mentor !== undefined && landingsInProject === 0;51 unmodified linesmodified:packages/project/src/deciders.ts+3 added-1 removed
98 unmodified lines99 } from "./attention/proposals.ts";100 import type { Proposed } from "./attention/proposals.ts";101 import { recordOf } from "./attention/record.ts";102 import { today } from "./attention/today.ts";103-import { standing } from "./attention/vouch.ts";103+import { capped, standing } from "./attention/vouch.ts";104 import { ClaimState } from "./claim.ts";105 import { DraftResult } from "./draft-runs.ts";106 import type { UnlandedRunEnv } from "./env-port.ts";107 import { ProjectEventInput } from "./events.ts";898 unmodified lines1006 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 lines1080 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 linesmodified:packages/project/src/project.ts+8 added-5 removed
190 unmodified lines191 import type { AnswerQueue, AnswerRuns, RunnableEffect } from "./answer-runs.ts";192 import { isStep } from "./answer-runs/steps.ts";193 import { openDecision } from "./attention/decisions.ts";194 import { recordOf } from "./attention/record.ts";195-import { mayClaim, standing } from "./attention/vouch.ts";195+import { capFor, capped, mayClaim, standing } from "./attention/vouch.ts";196 import {197 ClaimCommand,198 ClaimEffect,199 ClaimState,4043 unmodified lines4243 4244 return {4245 denounced: who === "denounced",4246 race: kind?.race ?? 1,4247+ standing: who,4248 vouched: admitted,4249 };4250 };4251 22 unmodified lines4274 4275 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 lines4499 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 linesmodified:packages/project/test/attention/proposals.test.ts+8 added
40 unmodified lines41 const 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 lines61 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 lines111 Result.fail(new CapReached({ cap: 2, limit: "proposals" }))112 );113 });114 115+ 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+ });120+121 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 linesmodified:packages/project/test/deciders.test.ts+18 added-3 removed
301 unmodified lines302 303 const onToday = yield* api.today(alice);304 const alarm = yield* scheduled;305 306+ // 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" });308 309+ yield* api.proposeAsk(dave, { want: "Trim spaces too" });310+311 const third = yield* api309- .proposeAsk(carol, { want: "Trim newlines too" })312+ .proposeAsk(dave, { want: "Trim newlines too" })313 .pipe(Effect.flip);314 315+ const beyondCap = yield* api316+ .proposeAsk(carol, { want: "Trim carriage returns too" })317+ .pipe(Effect.result, Effect.map(Result.isSuccess));318+319 yield* redOnMain(files);320 321 const accepted = yield* api.decide(alice, {322 choice: "accept",7 unmodified lines330 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 lines473 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 lines515 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