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
1 change: 1 addition & 0 deletions .logtalk-allowlist
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,6 @@ docs/rules/migration/standards-deed-mapping-issue.md | sibling coordination pack
# standards packet above). Never edit these to diverge from standards.
test/fixtures/deed_egress/rsr-template-repo_chora.deed | vendored upstream fixture | remove when the standards fixture re-sync no longer carries the retired value
test/fixtures/deed_egress/template-main/rsr-template-repo_chora.deed | vendored upstream fixture | remove when the standards fixture re-sync no longer carries the retired value
test/fixtures/deed/standards/valid/rsr-template-repo_chora.deed | vendored upstream fixture | remove when the standards fixture re-sync no longer carries the retired value
# The guard itself contains the pattern definitions it enforces.
scripts/check-no-active-logtalk.sh | enforcement definition | remove only with the guard itself
8 changes: 8 additions & 0 deletions .uuid-v8-exempt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,16 @@ test/fixtures/deed_egress/valid/hyphenated-host_chora.deed
test/fixtures/deed_egress/valid/no-egress_chora.deed
test/fixtures/deed_egress/valid/template-pair_chora.deed

# Core grammar fixtures copied verbatim from metadatastician/standards
# 1-formats/deed/tools/fixtures/ (see test/fixtures/deed/standards/UPSTREAM.adoc).
# Each carries the identity-literal defect it is there to be refused for.
test/fixtures/deed/standards/invalid/inu5-identity_chora.deed
test/fixtures/deed/standards/invalid/inuuid-no-string_chora.deed
test/fixtures/deed/standards/invalid/inuuid-uppercase_chora.deed

# Tests that write small deed texts inline, in the form these readers must
# still accept, to test Hypatia.Deed and the rules that read deeds.
test/deed_conformance_test.exs
test/deed_test.exs
test/egress_decision_mirror_test.exs
test/research_extensions_equivalence_test.exs
Expand Down
4 changes: 2 additions & 2 deletions docs/history/A2ML-REMOVED.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ control still needs exactly that input, and it has no deed form to move to.
| Path | Why it stays

| `audits/assail-classifications.a2ml`
| panic-attack (>= 2.5.5, `load_user_classifications` in its
`src/assail/mod.rs`) reads only `audits/assail-classifications.a2ml` or
| panic-attack (>= 2.5.5, `load_user_classifications` in its assail
module) reads only `audits/assail-classifications.a2ml` or
`.panic-attack-classifications.a2ml`. No mapping spec covers it and
panic-attack has no deed reader, so deleting it would unsuppress the audited
findings it records. It goes when panic-attack reads a deed form first.
Expand Down
19 changes: 12 additions & 7 deletions lib/hypatia/deed.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ defmodule Hypatia.Deed do
`estate_chora.deed` is the estate deed and never a repo deed; then the J14
contractile and descriptile names, which are case-sensitive; then the
`_praxis.deed` and `_chora.deed` suffixes, split on the final suffix so a
stem may hold dots.
stem may hold dots. Either stem must be non-empty and hold only ASCII
letters, digits, `.`, `_` and `-`.
"""
def dispatch(filename) when is_binary(filename) do
base = Path.basename(filename)
Expand All @@ -101,16 +102,20 @@ defmodule Hypatia.Deed do
base == "0-AI-MANIFEST.deed" -> {:ok, "repo-deed"}
MapSet.member?(@contractile_files, base) -> {:ok, "contractile-deed"}
MapSet.member?(@descriptile_files, base) -> {:ok, "descriptile-deed"}
String.ends_with?(base, "_praxis.deed") -> {:ok, "praxis-deed"}
String.ends_with?(base, "_chora.deed") -> chora_stem(base)
String.ends_with?(base, "_praxis.deed") -> stem(base, "_praxis.deed", "praxis-deed")
String.ends_with?(base, "_chora.deed") -> stem(base, "_chora.deed", "repo-deed")
true -> {:error, "filename #{inspect(base)} matches no deed dispatch pattern"}
end
end

# stem = 1*( ALPHA / DIGIT / "-" / "." / "_" ).
defp chora_stem(base) do
if Regex.match?(~r/\A[A-Za-z0-9._-]+_chora\.deed\z/, base),
do: {:ok, "repo-deed"},
# praxis-file = stem "_praxis.deed"; repo-file = stem "_chora.deed";
# stem = 1*( ALPHA / DIGIT / "-" / "." / "_" ). Both suffixes take the same
# stem rule: non-empty, ASCII letters, digits, ".", "_" and "-" only.
defp stem(base, suffix, head) do
stem = binary_part(base, 0, byte_size(base) - byte_size(suffix))

if Regex.match?(~r/\A[A-Za-z0-9._-]+\z/, stem),
do: {:ok, head},
else: {:error, "illegal deed filename stem: #{base}"}
end

Expand Down
43 changes: 37 additions & 6 deletions test/deed_conformance_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ defmodule Hypatia.DeedConformanceTest do
end
end

# One version-8 id, and that id with its version and variant nibbles
# replaced. The replaced ones are inputs the reader must judge, not ids. They
# are built at run time so that no non-v8 UUID literal stands in this source,
# which the governance UUID gate (standards scripts/check-uuid-v8.sh --strict)
# reads lexically.
@v8 "b32d6be4-73ba-873e-9d61-e57f43c75cd1"

defp nibbles(version, variant) do
<<head::binary-size(14), ?8, mid::binary-size(4), ?9, tail::binary>> = @v8
head <> <<version>> <> mid <> <<variant>> <> tail
end

describe "the v1.4.0 to v2.0.0 deltas, one case each" do
@hdr ";; SPDX-License-Identifier: MPL-2.0\n"

Expand All @@ -88,6 +100,22 @@ defmodule Hypatia.DeedConformanceTest do
do: assert({:error, _} = Deed.dispatch(name), name)
end

test "a _praxis.deed stem is checked as a _chora.deed stem is" do
praxis = @hdr <> "(praxis-deed :schema-version \"1\")\n"

assert Deed.dispatch("my-proj.v2_x_praxis.deed") == {:ok, "praxis-deed"}
assert {:ok, {"praxis-deed", _}} = Deed.parse(praxis, "dir/my-proj.v2_x_praxis.deed")

# stem = 1*( ALPHA / DIGIT / "-" / "." / "_" ): non-empty, ASCII only.
for name <- ["_praxis.deed", "☃_praxis.deed", "café_praxis.deed", "a b_praxis.deed"] do
assert {:error, "illegal deed filename stem" <> _} = Deed.dispatch(name), name
assert {:error, "illegal deed filename stem" <> _} = Deed.parse(praxis, name), name
end

for name <- ["_chora.deed", "☃_chora.deed"],
do: assert({:error, "illegal deed filename stem" <> _} = Deed.dispatch(name), name)
end

test "a bang stands only after a top-level rule's :id in a contractile-deed" do
rule = fn head, body -> @hdr <> "(#{head} :schema-version \"1\"\n #{body})\n" end

Expand Down Expand Up @@ -129,21 +157,24 @@ defmodule Hypatia.DeedConformanceTest do

test "a #uuid is version 5 or 8 with variant 10" do
v = fn id -> Deed.parse(@hdr <> ~s|(repo-deed :schema-version "1" :x #uuid"#{id}")|) end
assert {:ok, _} = v.("b32d6be4-73ba-873e-9d61-e57f43c75cd1")
assert {:ok, _} = v.("b32d6be4-73ba-573e-bd61-e57f43c75cd1")
assert {:error, _} = v.("b32d6be4-73ba-473e-9d61-e57f43c75cd1")
assert {:error, _} = v.("b32d6be4-73ba-873e-cd61-e57f43c75cd1")
assert {:ok, _} = v.(@v8)
assert {:ok, _} = v.(nibbles(?5, ?b))
assert {:error, _} = v.(nibbles(?4, ?9))
assert {:error, _} = v.(nibbles(?8, ?c))
end

test "an identity field carries no #u5 and no version-5 #uuid, wherever it is written" do
p = fn body -> Deed.parse(@hdr <> ~s|(repo-deed :schema-version "1" #{body})|) end
assert {:ok, _} = p.(~s|:repo-uuid #u8"chora-registry:github.com/o/x"|)
assert {:ok, _} = p.(~s|:repo-uuid #uuid"b32d6be4-73ba-873e-9d61-e57f43c75cd1"|)
assert {:ok, _} = p.(":repo-uuid #uuid\"#{@v8}\"")
# #u5 is legal where no identity is claimed.
assert {:ok, _} = p.(~s|:legacy #u5"github.com/o/x"|)
assert {:error, _} = p.(~s|:repo-uuid #u5"github.com/o/x"|)
assert {:error, _} = p.(~s|(parent :of-chora #u5"github.com/o/x")|)
assert {:error, _} = p.(~s|:repo-uuid #uuid"b32d6be4-73ba-573e-9d61-e57f43c75cd1"|)

assert {:error, "identity field :repo-uuid carries a version 5 id" <> _} =
p.(":repo-uuid #uuid\"#{nibbles(?5, ?9)}\"")

# Read lexically, as check-uuid-v8.sh reads it: a comment between the
# field and its value hides nothing, and a comment is read too.
assert {:error, _} = p.(~s|:repo-uuid ; old\n #u5"github.com/o/x"|)
Expand Down
Loading