Skip to content

Commit 91c33b6

Browse files
committed
test(P3-02.01): add bounded proc macro wire contract candidate
1 parent 87d05e9 commit 91c33b6

7 files changed

Lines changed: 569 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"formalAcceptedGates": 0,
3+
"formalAcceptedLeaves": 0,
4+
"fullP3Closure": false,
5+
"macroExecutions": 0,
6+
"bindings": [
7+
{
8+
"path": "eng/prototypes/ProcWireCandidateV1/ProcWireCandidate.csproj",
9+
"sha256": "9B2F33EF32B4941158D98C8F042DEAFE32E823F3F5A2F46AD0A5DBD26431D28A"
10+
},
11+
{
12+
"path": "eng/prototypes/ProcWireCandidateV1/Contract.cs",
13+
"sha256": "5C39B13AA67A325B0E6FA4749F967E3709C8914108C3295524958DF069C56FB4"
14+
},
15+
{
16+
"path": "eng/prototypes/ProcWireCandidateV1/Program.cs",
17+
"sha256": "5E1B9F820A123634FB072D5A85D8DD950F72E73C00C6F7374245040B28FB4708"
18+
},
19+
{
20+
"path": "eng/prototypes/ProcWireCandidateV1/proc-wire.candidate.json",
21+
"sha256": "9A2AB5F9EC3BD8CA1152E10F541A14F77C4D90BD253B8A3EC37DA886859299CC"
22+
}
23+
],
24+
"passed": 24,
25+
"taskId": "P3-02.01.protocol-candidate",
26+
"scope": "ISOLATED_JSON_CONTRACT_VALIDATOR_ONLY",
27+
"tests": "artifacts/p1-supervision/resume-root-v56/calls/protocol-tests-3a2eec6ab79247dc803e9346ddc467fa/stdout.bin",
28+
"positiveEnvelopeKinds": 8,
29+
"hostExecutions": 0,
30+
"testSha256": "D857C6609A82E5C9FA3D39F0C256A2EC90D4CC2D3EAC96085FD59E2DD1FB7EB5",
31+
"denominator": 24,
32+
"formalAcceptanceAllowed": false,
33+
"negativeCases": 15,
34+
"localSdk": "10.0.402",
35+
"transportExecutions": 0,
36+
"unmetDependency": "P3-01",
37+
"callerCancellation": 1,
38+
"integration": "Byte-identical isolated source snapshot; final-SHA CI pending",
39+
"allResourceBoundariesProven": false
40+
}

‎docs/roadmap/P2-HANDOFF.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,3 +1343,5 @@ Round54 independent native growth input component is ✅ Complete: held/transien
13431343
Round56 P1-GATE.02 inventory component is ✅ Complete: strict local build and11 fixed checks pass (four original reports/112 ordered ID+source hashes, proposal28 and six new mutations). Prior baseline/eight mutations are retained without rerun. [Exact inventory proof](../evidence/p1/strict-cleanup-inventory-v1.json) preserves the unapproved proposal and unchanged28/168/56/callable7+2 denominators. This is inventory validation only; generated cleanup semantics and all six P1 gates stay open.
13441344

13451345
Round56 original-handle lease component is ✅ Complete: strict build and real Windows A1/A2/A3 pass, including both forced-exception and cancellation cleanup. [Native ownership proof](../evidence/p1/original-handle-lease-v1.json) binds same observer handle transfer, receiver close, borrowed-handle survival and duplicate-transfer rejection; prior analyzer and path-precondition failures remain. Production acquisition, lifetime ancestry, growth reconciliation and legacy8/dual3 acceptance remain open; active20/cumulative1024 are unchanged.
1346+
1347+
Round56 P3-02.01 protocol candidate component is ✅ Complete: strict trim/AOT-analyzed local build and24/24 contract checks pass (eight envelope kinds,15 rejects and caller cancellation). [Candidate proof](../evidence/p3/proc-wire-candidate-v1.json) covers exact version, direction/kind, capabilities, fields and spans only; no transport/host/macro runs or complete budget-boundary proof follows. P3-01 dependency is unpassed; P3 formal leaves0/38 and gates0/4 remain unchanged.

‎docs/roadmap/P2-HANDOFF_zh.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,3 +1113,5 @@ root 负责共享注册容量、调用方集成、CI/门禁聚合、双语状
11131113
Round56 P1-GATE.02库存组件 ✅ 已完成:本地严格构建及11项固定检查通过(四份原报告/112条有序ID与源码哈希、28项提案及六项新变异)。历史基线/八项变异保留且未重跑。[精确库存证据](../evidence/p1/strict-cleanup-inventory-v1.json)保留未批准提案及原28/168/56/callable7+2分母。这仅验证库存;生成清理语义与P1六门禁仍开放。
11141114

11151115
Round56原句柄lease组件 ✅ 已完成:严格构建及真实Windows A1/A2/A3通过,包含强制异常与取消回收两个子项。[原生所有权证据](../evidence/p1/original-handle-lease-v1.json)绑定同一观察进程原句柄转移、接收方关闭、借用句柄存活及重复转移拒绝;历史分析器与路径前置条件失败保留。生产acquisition、生命周期祖先链、增长协调器及legacy8/dual3验收仍开放;active20/cumulative1024不变。
1116+
1117+
Round56 P3-02.01协议候选组件 ✅ 已完成:启用trim/AOT分析的本地严格构建及24/24契约检查通过(八种消息、15项拒绝及调用方取消)。[候选证据](../evidence/p3/proc-wire-candidate-v1.json)仅覆盖精确版本、方向/类型、能力、字段及span;无transport/host/macro运行或全部预算边界证明。P3-01依赖未通过;P3正式叶子0/38、门禁0/4不变。
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
using System.Diagnostics;
2+
using System.Text;
3+
using System.Text.Json;
4+
5+
namespace RustSharp.ProcWireCandidate;
6+
7+
/// <summary>Stateless JSON contract checks only; no transport, host, filesystem capability or macro execution.</summary>
8+
public static class Contract
9+
{
10+
public const string Protocol = "rustsharp.proc-wire.candidate.v1";
11+
public const int MaximumFrameBytes = 65_536;
12+
public const int MaximumTokens = 256;
13+
public const int MaximumSpans = 256;
14+
public const int MaximumDocuments = 8;
15+
public const int MaximumDiagnostics = 16;
16+
public const int MaximumTokenBytes = 256;
17+
public const int MaximumDiagnosticBytes = 2_048;
18+
public const int MaximumDelimiterDepth = 16;
19+
public const int MaximumJsonDepth = 12;
20+
public const int MaximumOperations = 8_192;
21+
public const int TimeoutMilliseconds = 1_000;
22+
private static readonly string[] Capabilities = ["token-tree-v1", "span-v1", "diagnostics-v1", "cancellation-v1"];
23+
24+
public static Result Validate(string json, CancellationToken cancellationToken = default)
25+
{
26+
ArgumentNullException.ThrowIfNull(json); cancellationToken.ThrowIfCancellationRequested();
27+
if (json.Length > MaximumFrameBytes || Encoding.UTF8.GetByteCount(json) > MaximumFrameBytes) return Invalid("RSPROC1090", "Frame byte budget exceeded.");
28+
var validator = new Validator(Stopwatch.StartNew(), cancellationToken);
29+
try
30+
{
31+
using JsonDocument document = JsonDocument.Parse(json, new JsonDocumentOptions { MaxDepth = MaximumJsonDepth });
32+
JsonElement root = document.RootElement; validator.Tree(root, 0);
33+
validator.Properties(root, ["protocolVersion", "requestId", "direction", "kind", "capabilities", "documents", "spans", "tokens", "diagnostics"]);
34+
if (validator.Text(root, "protocolVersion", 64) != Protocol) return Invalid("RSPROC1002", "Unsupported exact wire version.");
35+
_ = validator.Text(root, "requestId", 64);
36+
string direction = validator.Text(root, "direction", 32), kind = validator.Text(root, "kind", 32);
37+
string expectedDirection = kind switch
38+
{
39+
"hello" or "expand" or "cancel" => "compiler-to-host",
40+
"ready" or "expanded" or "diagnostic" or "error" or "cancelled" => "host-to-compiler",
41+
_ => throw new FormatException("Unsupported envelope kind."),
42+
};
43+
validator.Require(direction == expectedDirection, "Envelope direction/kind mismatch.");
44+
JsonElement capabilities = validator.Array(root, "capabilities", 4);
45+
var seenCapabilities = new HashSet<string>(StringComparer.Ordinal);
46+
foreach (JsonElement value in capabilities.EnumerateArray())
47+
{
48+
validator.Step(); string capability = value.GetString() ?? throw new FormatException("Null capability.");
49+
if (!Capabilities.Contains(capability, StringComparer.Ordinal)) return Invalid("RSPROC1001", "Unsupported capability: " + capability);
50+
validator.Require(seenCapabilities.Add(capability), "Duplicate capability.");
51+
}
52+
bool handshake = kind is "hello" or "ready";
53+
validator.Require(handshake ? seenCapabilities.SetEquals(Capabilities) : seenCapabilities.Count == 0, "Capabilities are exact at handshake and empty in later envelopes.");
54+
var documents = new Dictionary<string, int>(StringComparer.Ordinal);
55+
JsonElement sourceDocuments = validator.Array(root, "documents", MaximumDocuments);
56+
foreach (JsonElement value in sourceDocuments.EnumerateArray())
57+
{
58+
validator.Step(); validator.Properties(value, ["id", "utf16Length"]);
59+
string id = validator.Text(value, "id", 64); int length = value.GetProperty("utf16Length").GetInt32();
60+
validator.Require(length is >= 0 and <= MaximumFrameBytes && documents.TryAdd(id, length), "Invalid or duplicate source document.");
61+
}
62+
JsonElement spans = validator.Array(root, "spans", MaximumSpans);
63+
foreach (JsonElement value in spans.EnumerateArray())
64+
{
65+
validator.Step(); validator.Properties(value, ["documentId", "start", "length"]);
66+
string id = validator.Text(value, "documentId", 64); int start = value.GetProperty("start").GetInt32(), length = value.GetProperty("length").GetInt32();
67+
validator.Require(documents.TryGetValue(id, out int size) && start >= 0 && length >= 0 && start <= size - length, "Span outside its declared UTF16 document bounds.");
68+
}
69+
JsonElement tokens = validator.Array(root, "tokens", MaximumTokens);
70+
var delimiters = new Stack<char>();
71+
foreach (JsonElement token in tokens.EnumerateArray())
72+
{
73+
validator.Step(); validator.Properties(token, ["kind", "text", "spanIndex"]);
74+
string tokenKind = validator.Text(token, "kind", 32), text = validator.Text(token, "text", MaximumTokenBytes);
75+
validator.Require(tokenKind is "identifier" or "literal" or "punctuation" or "open" or "close", "Unknown token kind.");
76+
int spanIndex = token.GetProperty("spanIndex").GetInt32(); validator.Require(spanIndex >= 0 && spanIndex < spans.GetArrayLength(), "Token span index is invalid.");
77+
if (tokenKind == "open")
78+
{
79+
validator.Require(text.Length == 1 && text[0] is '(' or '[' or '{' && delimiters.Count < MaximumDelimiterDepth, "Open delimiter/depth limit is invalid.");
80+
delimiters.Push(text[0]);
81+
}
82+
else if (tokenKind == "close")
83+
{
84+
validator.Require(text.Length == 1 && text[0] is ')' or ']' or '}' && delimiters.Count > 0, "Unmatched close delimiter.");
85+
char open = delimiters.Pop(); validator.Require((open, text[0]) is ('(', ')') or ('[', ']') or ('{', '}'), "Delimiter kind mismatch.");
86+
}
87+
}
88+
validator.Require(delimiters.Count == 0, "Unclosed delimiter tree.");
89+
JsonElement diagnostics = validator.Array(root, "diagnostics", MaximumDiagnostics);
90+
foreach (JsonElement diagnostic in diagnostics.EnumerateArray())
91+
{
92+
validator.Step(); validator.Properties(diagnostic, ["severity", "code", "message", "spanIndex"]);
93+
string severity = validator.Text(diagnostic, "severity", 32); validator.Require(severity is "error" or "warning" or "note", "Unknown diagnostic severity.");
94+
_ = validator.Text(diagnostic, "code", 64); _ = validator.Text(diagnostic, "message", MaximumDiagnosticBytes);
95+
int index = diagnostic.GetProperty("spanIndex").GetInt32(); validator.Require(index == -1 || index >= 0 && index < spans.GetArrayLength(), "Invalid diagnostic span index.");
96+
if (kind == "error") validator.Require(severity == "error", "Error envelope requires error diagnostics.");
97+
}
98+
bool expansion = kind is "expand" or "expanded", diagnosticEnvelope = kind is "diagnostic" or "error";
99+
validator.Require(expansion ? tokens.GetArrayLength() > 0 && documents.Count > 0 && spans.GetArrayLength() > 0 : tokens.GetArrayLength() == 0, "Token payload is inappropriate for envelope kind.");
100+
validator.Require(diagnosticEnvelope ? diagnostics.GetArrayLength() > 0 : diagnostics.GetArrayLength() == 0, "Diagnostic payload is inappropriate for envelope kind.");
101+
if (handshake || kind is "cancel" or "cancelled") validator.Require(documents.Count == 0 && spans.GetArrayLength() == 0, "Control envelope cannot carry source payload.");
102+
validator.Step(); return new(true, string.Empty, string.Empty, kind, tokens.GetArrayLength(), spans.GetArrayLength());
103+
}
104+
catch (Exception exception) when (exception is JsonException or InvalidOperationException or FormatException or KeyNotFoundException or OverflowException or TimeoutException)
105+
{ return Invalid("RSPROC1090", exception.Message); }
106+
}
107+
private static Result Invalid(string code, string message) => new(false, code, message, string.Empty, 0, 0);
108+
private sealed class Validator(Stopwatch clock, CancellationToken cancellationToken)
109+
{
110+
private int _operations;
111+
internal void Step() { cancellationToken.ThrowIfCancellationRequested(); if (++_operations > MaximumOperations || clock.ElapsedMilliseconds >= TimeoutMilliseconds) throw new TimeoutException("Wire validation operation/deadline budget exceeded."); }
112+
internal void Require(bool condition, string message) { Step(); if (!condition) throw new FormatException(message); }
113+
internal string Text(JsonElement value, string name, int maximumBytes) { Step(); string? text = value.GetProperty(name).GetString(); Require(!string.IsNullOrWhiteSpace(text) && Encoding.UTF8.GetByteCount(text) <= maximumBytes, "Missing, empty or oversized text: " + name); return text!; }
114+
internal JsonElement Array(JsonElement value, string name, int maximum) { Step(); JsonElement array = value.GetProperty(name); Require(array.ValueKind == JsonValueKind.Array && array.GetArrayLength() <= maximum, "Array type/count limit: " + name); return array; }
115+
internal void Properties(JsonElement value, string[] names)
116+
{
117+
Step(); var actual = new HashSet<string>(StringComparer.Ordinal);
118+
foreach (JsonProperty property in value.EnumerateObject()) { Step(); Require(actual.Add(property.Name), "Duplicate JSON property."); }
119+
Require(actual.SetEquals(names), "Missing or unexpected JSON property.");
120+
}
121+
internal void Tree(JsonElement value, int depth)
122+
{
123+
Step(); Require(depth <= MaximumJsonDepth, "JSON nesting depth exceeded.");
124+
if (value.ValueKind == JsonValueKind.Object)
125+
{
126+
var names = new HashSet<string>(StringComparer.Ordinal);
127+
foreach (JsonProperty property in value.EnumerateObject()) { Step(); Require(names.Add(property.Name), "Duplicate JSON property."); Tree(property.Value, depth + 1); }
128+
}
129+
else if (value.ValueKind == JsonValueKind.Array)
130+
{
131+
Require(value.GetArrayLength() <= MaximumTokens, "Generic array item budget exceeded.");
132+
foreach (JsonElement item in value.EnumerateArray()) Tree(item, depth + 1);
133+
}
134+
}
135+
}
136+
}
137+
public sealed record Result(bool IsSuccessful, string DiagnosticCode, string Message, string Kind, int TokenCount, int SpanCount)
138+
{ public bool FormalAcceptanceAllowed { get; } public int MacroCodeExecutions { get; } }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<IsTestProject>true</IsTestProject>
5+
<IsPackable>false</IsPackable>
6+
<IsAotCompatible>true</IsAotCompatible>
7+
<AssemblyName>RustSharp.ProcWireCandidate.Round56</AssemblyName>
8+
</PropertyGroup>
9+
</Project>

0 commit comments

Comments
 (0)