Skip to content
Open
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
48 changes: 48 additions & 0 deletions src/artifact_autopsy.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const std = @import("std");

/// This is a fixture for recipe consistency in artifact_autopsy, providing testing of invariants without implementing file-backed execution or touching GIP dispatch.
pub const RecipeConsistencyFixture = struct {
is_fixture_backed: bool = true,
is_file_backed: bool = false,
read_only: bool = true,
non_authorizing: bool = true,
proof_granted: bool = false,
support_granted: bool = false,
candidate_inconsistency: bool = false,
unknowns: bool = false,

pub fn init(has_inconsistency: bool, has_unknowns: bool) RecipeConsistencyFixture {
return .{
.candidate_inconsistency = has_inconsistency,
.unknowns = has_unknowns,
};
}
Comment on lines +14 to +19

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In Zig, struct literals are often preferred over simple init functions that just map parameters to fields. If you choose to keep the init function, consider renaming the parameters to match the field names (candidate_inconsistency and unknowns) to avoid ambiguity at the call site (the 'boolean trap'). Additionally, using const Self = @This(); and returning Self is the standard idiom for initializers in Zig.

    pub fn init(candidate_inconsistency: bool, unknowns: bool) RecipeConsistencyFixture {
        return .{
            .candidate_inconsistency = candidate_inconsistency,
            .unknowns = unknowns,
        };
    }

};

test "recipe_consistency fixture is fixture-backed and not file-backed" {
const fixture = RecipeConsistencyFixture.init(false, false);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since RecipeConsistencyFixture defines default values for all its fields, you can use the struct literal syntax RecipeConsistencyFixture{} instead of calling init(false, false). This is more idiomatic in Zig when you only need the default state and avoids passing redundant arguments that match the defaults. This observation applies to the other test cases in this file as well.

    const fixture = RecipeConsistencyFixture{};

try std.testing.expect(fixture.is_fixture_backed);
try std.testing.expect(!fixture.is_file_backed);
}

test "recipe_consistency fixture is read-only and non-authorizing" {
const fixture = RecipeConsistencyFixture.init(false, false);
try std.testing.expect(fixture.read_only);
try std.testing.expect(fixture.non_authorizing);
}

test "recipe_consistency fixture grants no proof or support" {
const fixture = RecipeConsistencyFixture.init(false, false);
try std.testing.expect(!fixture.proof_granted);
try std.testing.expect(!fixture.support_granted);
}

test "recipe_consistency fixture has candidate inconsistency/unknowns if current fixture includes them" {
const fixture_with_issues = RecipeConsistencyFixture.init(true, true);
try std.testing.expect(fixture_with_issues.candidate_inconsistency);
try std.testing.expect(fixture_with_issues.unknowns);

const fixture_clean = RecipeConsistencyFixture.init(false, false);
try std.testing.expect(!fixture_clean.candidate_inconsistency);
try std.testing.expect(!fixture_clean.unknowns);
}