Documentation
¶
Overview ¶
Package coord is the coordination pass of itd-2610170634394993: a pure function that reads a snapshot of the records on the shared remote and returns the decisions they call for (spc-2610230758581403, step 1).
The pass holds no state and keeps no clock of its own. The time it judges by is part of the snapshot, and every deadline it names is derived from the records when they are read (dcn-2610180720366282), so any session that reads the same records reaches the same decisions, in whatever order it read them, and a pass stopped part-way through acting on them, re-run from the records its acts left, gives again every decision but those for the changes its acts recorded as queued.
What it decides: an open change no dependency holds (every one it names has merged) is queued. One that depends directly on a change closed unmerged or on a number with no record, or is on or reaches a cycle of unmerged changes, itself included, is refused at once, naming the numbers and the cause (story 2), since no wait can release it. Any other open change waiting on another waits until its recorded start plus the stated wait limit; a wait at or past that deadline, one with no recorded start, or one whose recorded start is later than the records' time is refused with a reason naming what it waited on (adr-2610222026262980, rule 1). Only open changes are decided: a queued, merged or closed change gets no decision, and so a queued change with a closed or missing dependency, or on a cycle, gets none either. Claims and the record version are later steps of the spec.
Reading the dependency line is ParseDependsOn's, in depends.go.
Its first caller is land's enqueue step (internal/core/landing/depends.go), which reads its own pull request and its dependencies from the forge, passes them to Pass and acts on its own pull request's decision (spc-2610230758581403, step 2a; dcn-2611101309224327).
Index ¶
Constants ¶
const MaxWaitLimit = 24 * time.Hour
MaxWaitLimit is the longest wait limit a snapshot may state. A longer one is refused whole, as a limit that is not positive is, so no record can make a wait open-ended by stating a limit of centuries.
const RefusedAtOnce = "refused at once, since no wait can release it: "
RefusedAtOnce begins the reason of a refusal no wait can release (a closed or missing dependency, or a cycle), so a caller can tell it from a refusal of the wait's start or deadline, which leave Until zero too.
Variables ¶
This section is empty.
Functions ¶
func ParseDependsOn ¶
ParseDependsOn reads the dependencies a pull request body declares (dcn-2610180720362692): each line exactly `Depends-On: #N` or `Depends-On: #N, #N, ...`, the numbers separated by commas with optional spaces or tabs around each, the body split on newlines with one trailing carriage return stripped from each line. The numbers of every accepted line are joined, ascending and once each, nil for none.
The body is untrusted, so the parse fails closed and no text of it reaches the error: more than maxDepends distinct numbers, and a body over maxBodyBytes, are refused, and so is any line that is not an accepted line but looks like one in a wrong shape, by its 1-based line number alone.
To find those, each such line is first stripped by scanForm of every character in Unicode categories Cf (format), Mn (non-spacing marks) and Me (enclosing marks), of the Hangul fillers U+115F, U+1160 and U+3164, and of every NUL and backslash. The tests pin these of them: the zero-width space, zero-width joiner, word joiner, soft hyphen and byte-order mark (Cf); the combining grapheme joiner U+034F, the variation selector U+FE0F and the Mongolian free variation selector U+180B (Mn); the enclosing circle U+20DD (Me); the three fillers; NUL; and the backslash. The stripped line is then judged by the scan:
A line that is not an accepted line is refused when, with the characters the scan drops removed (format characters, non-spacing and enclosing marks, three Hangul fillers, NUL and backslash), it holds, in any case (the long s, U+017F, counts as s), depends-on with an ASCII hyphen anywhere, or depend or depends, then any run, or none, of hyphens, underscores, ASCII spaces, tabs, Unicode dashes (category Pd), minus signs (U+2212) or hyphen bullets (U+2043), then on, then any run, or none, of ASCII spaces or tabs and nothing else, then a colon. Any other line is read as declaring none, among them: a line with anything else between the words, such as another word or a no-break space (It depends heavily on: the queue), or between on and the colon, such as a number (This depends on #5: it needs the schema); a line with a spacing mark (category Mc), such as U+0903, inside a word; a line with no colon whose words are not depends-on with an ASCII hyphen, such as words joined by a space, a spaced hyphen, an underscore or another kind of hyphen or dash, U+2011 and the en dash among them (Depends on #5, Depends - On #5, depends_on #5); and a line with other wording for a dependency (Blocked by #5, Requires #5). A dependency is declared only by an accepted line, so write the accepted line.
Nothing else is decoded, so these are read past as no dependency, each pinned by a test: an HTML entity (Depends-On); a letter from another script that looks like a Latin one; a fullwidth letter; another word, or any space but an ASCII space or tab, between the words; a number, or a non-ASCII space, between on and the colon (Depends On, a no-break space, then a colon); a form with no colon whose words are not depends-on with an ASCII hyphen (Depends on #5, Depends - On #5, depends_on #5, depend-on #5, and the words joined by a non-breaking hyphen U+2011 or an en dash); Depends: alone; other words for a dependency; an invisible character outside the stripped set, such as the halfwidth Hangul filler U+FFA0; and the word split by a newline, a lone carriage return, a line separator U+2028, a next-line character U+0085 or a byte that is not valid UTF-8. The scan is for mistakes, not for an author set against it: an author who wants no hold can leave the line out.
The scan does not tell prose from a declaration: a mention of the words in prose is refused like any other line in a wrong shape, by line number and in the safe direction, since a wrong reading of no dependency can queue a change its author meant to hold. So these are refused: ordinary prose with a colon after the words (The order depends on: the queue), prose naming the trailer (the Depends-On trailer), a quoted or indented compose key (depends_on:), a path or URL holding depends-on, a word that begins with it (depends-only), a Windows path such as C:\depends\on: once its backslashes are dropped, and a word written with a decomposed accent, such as dépend on: with its accent a combining mark (Mn), once the mark is dropped; the same word with its accent precomposed (U+00E9) is read past. The error tells the author that the line holds the words but is not in the accepted shape, gives that shape (Depends-On: #<number> alone on a line, more numbers separated by commas), and says prose in the body must not use the words, so the sentence is reworded or the line written in that shape.
Lines are judged one at a time, with no regard for markdown. A well-formed line inside a code fence or an HTML comment that spans several lines is read as a dependency, which holds its change rather than freeing it. A line quoting a placeholder that names depends-on in the wrong shape, such as <!-- Depends-On: #N -->, is refused, so a body that keeps a template's placeholder is refused until the placeholder is edited or removed.
land's dependency check (internal/core/landing/depends.go) calls it on each pull request body it reads.
Types ¶
type Action ¶
type Action string
Action is what a decision says to do with a change.
const ( // ActionQueue: no dependency holds the change. It says nothing of whether // the change is ready or the caller's to queue (Records). ActionQueue Action = "queue" // ActionWait: the change waits on WaitsOn until Until. ActionWait Action = "wait" // ActionRefuse: the change is refused, for Reason. ActionRefuse Action = "refuse" )
The actions a decision can carry.
type Change ¶
type Change struct {
// Number is the change's pull request number.
Number int
// State is where the change stands.
State State
// DependsOn names the changes this one waits on, already read from its
// record. A number with no record of its own in the snapshot refuses the
// change at once; why there is none is the caller's to say before the
// pass.
DependsOn []int
// WaitingSince is the recorded time the change's wait began, the start
// its deadline is derived from. The caller writes it once, before the
// first pass that finds the change waiting, keeps that first start and
// never moves it, and takes it from a source the waiting agent cannot
// rewrite. A start re-stamped at each pass waits forever, and a pure pass
// cannot see that it was. A waiting change with no recorded start is
// refused, since no deadline can be derived for it. A start later than
// the records' Now is refused too, with no allowance for clock skew; any
// allowance is the caller's to make before the pass.
WaitingSince time.Time
}
Change is one change's record as the pass reads it.
type Decision ¶
type Decision struct {
// Change is the change's number.
Change int
// Action is what to do with it.
Action Action
// WaitsOn lists the dependencies not yet merged, ascending and once each,
// for a wait or a refusal.
WaitsOn []int
// Until is the wait's deadline in UTC, for a wait, and for a refusal at
// or past its deadline. It is zero for a refusal at once and for a
// refusal of a change with no recorded start or with one later than the
// records' time.
Until time.Time
// Reason says why a refusal was made.
Reason string
}
Decision is the pass's ruling on one change.
func Pass ¶
Pass reads the records and returns one decision for each open change, ordered by change number; queued, merged and closed changes need none. A snapshot it cannot judge is refused whole: no time, a wait limit that is not positive or is above MaxWaitLimit, more than maxChanges changes, a change with a number of zero or less, one read twice, an unknown state, more than maxDependsRead dependency numbers as read, more than maxDepends distinct dependencies, or a dependency numbered zero or less. A snapshot over maxChanges is refused on its count, its changes unread; a change over maxDependsRead on its count, its dependencies unread; and a change over maxDepends on its count, its dependencies' numbers unjudged. The one error names the defects found, sorted and once each, at most maxNamed, then how many more, so it is the same whatever order the records were read in, and it quotes an unknown state cut to maxStateRunes. Pass does not change the records it reads.
A caller whose whole pass is refused refuses its own act, arms nothing, and names the defect. It never sets the defective record aside and goes on, since a dependency set aside would read as satisfied.
type Records ¶
type Records struct {
// Now is the time the records were read at, which the pass judges by.
Now time.Time
// WaitLimit is how long a change may wait on another before its wait is
// refused: more than zero and at most MaxWaitLimit.
WaitLimit time.Duration
// Changes is every change record read.
Changes []Change
}
Records is the snapshot one pass reads. The records are written by other agents, so the pass judges these fields before deciding anything: the time, the wait limit, how many changes there are, each change's number, a number read twice, the state against the set of known states, how many dependency numbers each change carries as read, how many distinct ones and each one's number, and each start against Now. A field it cannot judge refuses the change or the whole snapshot, never queues. That a change is merged or queued is taken as the caller's verified fact, not judged: land takes it from the forge's answer, never from a pull request body.
The snapshot must hold only changes the caller is entitled to queue: a queue decision says only that no dependency holds the change, not whose change it is or that it is ready. Rebuilding a dependant on the default branch and the full test run before it is queued stay the caller's (the spec's step 2b).