Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 37 additions & 25 deletions dag/gunbc/merge_admission_produce.dag
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,12 @@ fn receipt_wire_v2_pr_number(lines: List<String>) -> ReceiptWirePrNumber {
if length(lines) == 6 {
WirePrAbsent
} else {
match parse_int(s: lines.skip(n: 6).first()) {
Present { value: n } => WirePrPresent { value: n }
match lines.skip(n: 6).first() {
Present { value: pr_line } =>
match parse_int(s: pr_line) {
Present { value: n } => WirePrPresent { value: n }
Absent => WirePrMalformed
}
Absent => WirePrMalformed
}
}
Expand Down Expand Up @@ -125,29 +129,37 @@ fn parse_receipt_wire_v2(text: String) -> MergeAdmissionReceiptV2? {
match parse_gate_roster_hash_wire(line: lines.skip(n: 2).first()) {
Absent => none
Present { value: gate_roster_hash } =>
match receipt_wire_v2_pr_number(lines: lines) {
WirePrMalformed => none
WirePrAbsent =>
Present {
value: MergeAdmissionReceiptV2 {
attempt_id: attempt,
pr_number: none,
tested_head_sha: lines.skip(n: 4).first(),
tested_base_commit_sha: lines.skip(n: 5).first(),
gate_roster_hash: gate_roster_hash,
conclusion: conclusion,
}
}
WirePrPresent { value: n } =>
Present {
value: MergeAdmissionReceiptV2 {
attempt_id: attempt,
pr_number: Present { value: n },
tested_head_sha: lines.skip(n: 4).first(),
tested_base_commit_sha: lines.skip(n: 5).first(),
gate_roster_hash: gate_roster_hash,
conclusion: conclusion,
}
match lines.skip(n: 4).first() {
Absent => none
Present { value: head_line } =>
match lines.skip(n: 5).first() {
Absent => none
Present { value: base_commit_line } =>
match receipt_wire_v2_pr_number(lines: lines) {
WirePrMalformed => none
WirePrAbsent =>
Present {
value: MergeAdmissionReceiptV2 {
attempt_id: attempt,
pr_number: none,
tested_head_sha: head_line,
tested_base_commit_sha: base_commit_line,
gate_roster_hash: gate_roster_hash,
conclusion: conclusion,
}
}
WirePrPresent { value: n } =>
Present {
value: MergeAdmissionReceiptV2 {
attempt_id: attempt,
pr_number: Present { value: n },
tested_head_sha: head_line,
tested_base_commit_sha: base_commit_line,
gate_roster_hash: gate_roster_hash,
conclusion: conclusion,
}
}
}
}
}
}
Expand Down
26 changes: 19 additions & 7 deletions dag/gunbc/merge_admission_subject.dag
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,26 @@ fn parse_tested_subject_wire(text: String) -> TestedSubject? {
} else {
match walk_attempt_id(raw: lines.skip(n: 1).first()) {
Absent => none
Present { value: attempt } => Present {
value: TestedSubject {
attempt_id: attempt,
base_ref: lines.skip(n: 2).first(),
head_sha: lines.skip(n: 3).first(),
base_commit_sha: lines.skip(n: 4).first(),
Present { value: attempt } =>
match lines.skip(n: 2).first() {
Absent => none
Present { value: base_ref_line } =>
match lines.skip(n: 3).first() {
Absent => none
Present { value: head_line } =>
match lines.skip(n: 4).first() {
Absent => none
Present { value: base_commit_line } => Present {
value: TestedSubject {
attempt_id: attempt,
base_ref: base_ref_line,
head_sha: head_line,
base_commit_sha: base_commit_line,
}
}
}
}
}
}
}
}
}
41 changes: 31 additions & 10 deletions dag/test/claim/merge_admission_attempt_witness_test.dag
Original file line number Diff line number Diff line change
Expand Up @@ -607,17 +607,30 @@ fn v2_refuses(text: String) -> Bool {
match parse_receipt_wire_v2(text: text) { Present { value: _ } => false Absent => true }
}

// Positive control: the same builder with every line correct MUST parse, or every row below is
// satisfied by a wire that was malformed for some other reason.
test fn wire_v2_built_from_explicit_lines_parses() -> Bool {
// Positive control, asserted at CARRIER GRAIN rather than on the verdict. A parser that returns
// `Present` before and after a rewrite while binding a different head SHA, attempt id, base commit
// or roster hash is NOT a no-op, and a `Present { value: _ } => true` row cannot see that. Every
// field the accepted class carries is asserted, so a rewrite that reads the wrong line -- an
// off-by-one in a `skip`, a field crossed with its neighbour -- goes red here rather than passing
// as an unchanged verdict.
test fn wire_v2_built_from_explicit_lines_parses_with_every_field_bound() -> Bool {
match parse_receipt_wire_v2(text: wire_v2_with_lines(
schema: merge_admission_receipt_schema_v2,
attempt: attempt_a_raw,
roster: render_gate_roster_hash_wire(hash: roster_fx()),
conclusion: good_v2_lines_conclusion(),
head: head_sha_fx,
base: base_commit_fx,
)) { Present { value: _ } => true Absent => false }
)) {
Present { value: parsed } =>
((parsed.attempt_id as String) == attempt_a_raw)
&& (parsed.tested_head_sha == head_sha_fx)
&& (parsed.tested_base_commit_sha == base_commit_fx)
&& (parsed.gate_roster_hash == roster_fx())
&& match parsed.pr_number { Absent => true Present { value: _ } => false }
&& match parsed.conclusion { Success => true _ => false }
Absent => false
}
}

test fn wire_v2_refuses_a_wrong_schema_line() -> Bool {
Expand Down Expand Up @@ -671,14 +684,14 @@ test fn wire_v2_refuses_a_blank_base_commit_line() -> Bool {
// same defect one parser over from the one the mutation control caught.
test fn object_id_wire_accepts_a_valid_sha1_wire() -> Bool {
match parse_git_object_id_wire(raw: "sha1:abc1234def5678901234567890abcd1234567890") {
Present { value: _ } => true
Present { value: oid } => git_object_id_wire_hex(oid: oid) == "abc1234def5678901234567890abcd1234567890"
Absent => false
}
}

test fn object_id_wire_accepts_a_valid_sha256_wire() -> Bool {
match parse_git_object_id_wire(raw: "sha256:abc1234def5678901234567890abcd12abc1234def5678901234567890abcd12") {
Present { value: _ } => true
Present { value: oid } => git_object_id_wire_hex(oid: oid) == "abc1234def5678901234567890abcd12abc1234def5678901234567890abcd12"
Absent => false
}
}
Expand All @@ -704,16 +717,24 @@ fn subject_refuses(text: String) -> Bool {
match parse_tested_subject_wire(text: text) { Present { value: _ } => false Absent => true }
}

// Positive control for the builder, without which every refusal row below could be satisfied by a
// wire malformed for some other reason.
test fn subject_wire_built_from_explicit_lines_parses() -> Bool {
// Positive control for the builder, at carrier grain for the same reason as the receipt one above:
// `base_ref`, `head_sha` and `base_commit_sha` are three consecutive lines, so a rewrite that reads
// the wrong one keeps the verdict and changes the value.
test fn subject_wire_built_from_explicit_lines_parses_with_every_field_bound() -> Bool {
match parse_tested_subject_wire(text: subject_wire_with_lines(
schema: merge_admission_tested_subject_schema,
attempt: attempt_a_raw,
base_ref: "origin/main",
head: head_sha_fx,
base_commit: base_commit_fx,
)) { Present { value: _ } => true Absent => false }
)) {
Present { value: parsed } =>
((parsed.attempt_id as String) == attempt_a_raw)
&& (parsed.base_ref == "origin/main")
&& (parsed.head_sha == head_sha_fx)
&& (parsed.base_commit_sha == base_commit_fx)
Absent => false
}
}

test fn subject_wire_refuses_a_wrong_schema_line() -> Bool {
Expand Down
Loading