Skip to content
Draft
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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,12 @@ jobs:
- run: cargo clippy --all-targets -- -D warnings
- run: cargo build --verbose
- run: cargo test --verbose

audit:
name: cargo-audit (dependency advisories)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: rustsec/audit-check@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
107 changes: 42 additions & 65 deletions .github/workflows/spec-drift-guard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,70 @@ on:
- "specs/**"
- "gen/**"
- "build.rs"
- ".t27c-version"
- ".github/workflows/spec-drift-guard.yml"

# Rebuild t27c from upstream master and regenerate every committed backend
# under gen/<target>/<spec>.<ext> from specs/<spec>.t27. If any committed
# output disagrees with the freshly generated output, the job fails with a
# diff so drift between the SSOT and generated code cannot land silently.
# PHYSICAL GUARD for the golden pipeline: specs/*.t27 -> t27c gen-rust -> gen/rust.
#
# Covered specs (68) × backends (3) = 204 drift checks:
# wire.t27 → gen/{rust,wire.rs} gen/{zig,wire.zig} gen/{c,wire.c}
# hello.t27 → gen/{rust,hello.rs} gen/{zig,hello.zig} gen/{c,hello.c}
# etx.t27 → gen/{rust,etx.rs} gen/{zig,etx.zig} gen/{c,etx.c}
# The compiler is PINNED (.t27c-version). This job rebuilds t27c at exactly that
# commit, regenerates every gen/rust/*.rs from specs/*.t27, and fails on ANY byte
# difference against the committed output. That makes three classes of the
# recurring breakage impossible to land:
# 1. committing gen/rust produced by a stale/wrong t27c (the 2026-07-07 break),
# 2. hand-editing gen/rust directly,
# 3. editing a spec without regenerating.
# It then builds + tests the tree so a green gen set that does not compile is
# also caught. Rust is NEVER written by hand in gen/; it is generated only.
#
# ExprCast is lowered in all three backends via t27#1320 (Rust) + t27#1337 (Zig+C).
# See docs/T27_FIRST_MIGRATION.md for the SSOT contract.
# Only the rust backend is checked -- the gen/zig and gen/c backends were removed
# from the tree, so the old "68 x 3 backends" guard was checking deleted paths.
# Anchor: phi^2 + phi^-2 = 3.

jobs:
regenerate-and-diff:
name: drift check (68 specs × 3 backends)
drift:
name: gen/rust drift vs pinned t27c
runs-on: ubuntu-latest
steps:
- name: Checkout tri-net
uses: actions/checkout@v4
with:
path: tri-net

- name: Checkout t27 (SSOT compiler source)
- name: Read pinned t27c commit
id: pin
run: echo "sha=$(grep -vE '^[[:space:]]*#' .t27c-version | grep -oE '[0-9a-f]{40}' | head -1)" >> "$GITHUB_OUTPUT"

- name: Checkout t27 at pinned commit
uses: actions/checkout@v4
with:
repository: gHashTag/t27
ref: master
ref: ${{ steps.pin.outputs.sha }}
path: t27

- name: Install stable Rust toolchain
uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@stable

- name: Build t27c (release)
working-directory: t27
run: cargo build --release --manifest-path bootstrap/Cargo.toml --bin t27c
- name: Build pinned t27c
run: cargo build --release -p t27c --manifest-path t27/Cargo.toml

- name: Drift check — Rust (all specs)
working-directory: tri-net
- name: Regenerate every gen/rust from specs
run: |
T27C=../t27/target/release/t27c
STATUS=0
for spec in wire hello etx crc16 byte_utils mesh_routing key_management frame_buffer packet_queue congestion_control flow_control self_healing trust_manager timer transport_tx_fsm redundancy_management fault_detection lite_crypto network_metrics m3_multihop link_statistics access_control bandwidth_allocator cache_management compression_engine cross_layer_optimizer energy_aware_routing adaptive_retry link_quality_monitor multipath_router auto_config adaptive_routing anomaly_detector api_documenter area_optimization docs_generator fpga_synthesis_report health_dashboard health_monitoring integration_tests load_predictor local_processing mesh_node_sim mesh_protocol_stack multipath_routing network_coding network_orchestrator network_simulator olsr_routing pattern_predictor performance_benchmarks performance_profiler power_monitoring production_deployment production_scenarios quarantine_manager resource_scheduler swarm_coordinator test_framework timing_closure topology_visualizer traffic_animator failure_predictor hardware_validation integration_framework network_analytics packet_loss_injection test_validator; do
$T27C gen-rust specs/${spec}.t27 > /tmp/${spec}_regen.rs
if ! diff -u gen/rust/${spec}.rs /tmp/${spec}_regen.rs; then
echo "::error file=gen/rust/${spec}.rs::DRIFT: gen/rust/${spec}.rs != t27c gen-rust specs/${spec}.t27"
echo "Fix: t27c gen-rust specs/${spec}.t27 > gen/rust/${spec}.rs"
STATUS=1
else
echo "gen/rust/${spec}.rs matches specs/${spec}.t27"
fi
T27C="t27/target/release/t27c"
for spec in specs/*.t27; do
name="$(basename "$spec" .t27)"
"$T27C" gen-rust "$spec" > "gen/rust/${name}.rs"
done
exit $STATUS

- name: Drift check — Zig (all specs)
working-directory: tri-net
- name: Fail on any drift
run: |
T27C=../t27/target/release/t27c
STATUS=0
for spec in wire hello etx crc16 byte_utils mesh_routing key_management frame_buffer packet_queue congestion_control flow_control self_healing trust_manager timer transport_tx_fsm redundancy_management fault_detection lite_crypto network_metrics m3_multihop link_statistics access_control bandwidth_allocator cache_management compression_engine cross_layer_optimizer energy_aware_routing adaptive_retry link_quality_monitor multipath_router auto_config adaptive_routing anomaly_detector api_documenter area_optimization docs_generator fpga_synthesis_report health_dashboard health_monitoring integration_tests load_predictor local_processing mesh_node_sim mesh_protocol_stack multipath_routing network_coding network_orchestrator network_simulator olsr_routing pattern_predictor performance_benchmarks performance_profiler power_monitoring production_deployment production_scenarios quarantine_manager resource_scheduler swarm_coordinator test_framework timing_closure topology_visualizer traffic_animator failure_predictor hardware_validation integration_framework network_analytics packet_loss_injection test_validator; do
$T27C gen specs/${spec}.t27 > /tmp/${spec}_regen.zig
if ! diff -u gen/zig/${spec}.zig /tmp/${spec}_regen.zig; then
echo "::error file=gen/zig/${spec}.zig::DRIFT: gen/zig/${spec}.zig != t27c gen specs/${spec}.t27"
echo "Fix: t27c gen specs/${spec}.t27 > gen/zig/${spec}.zig"
STATUS=1
else
echo "gen/zig/${spec}.zig matches specs/${spec}.t27"
fi
done
exit $STATUS
if ! git diff --quiet -- gen/rust/; then
echo "::error::gen/rust drifted from specs/*.t27 under the pinned t27c."
echo "Regenerate locally with the pinned t27c and commit the result;"
echo "never hand-edit gen/rust or use an unpinned compiler."
git --no-pager diff --stat -- gen/rust/
git --no-pager diff -- gen/rust/ | head -200
exit 1
fi
echo "gen/rust is in sync with specs under the pinned t27c."

- name: Drift check — C (all specs)
working-directory: tri-net
- name: Build + test the regenerated tree
run: |
T27C=../t27/target/release/t27c
STATUS=0
for spec in wire hello etx crc16 byte_utils mesh_routing key_management frame_buffer packet_queue congestion_control flow_control self_healing trust_manager timer transport_tx_fsm redundancy_management fault_detection lite_crypto network_metrics m3_multihop link_statistics access_control bandwidth_allocator cache_management compression_engine cross_layer_optimizer energy_aware_routing adaptive_retry link_quality_monitor multipath_router auto_config adaptive_routing anomaly_detector api_documenter area_optimization docs_generator fpga_synthesis_report health_dashboard health_monitoring integration_tests load_predictor local_processing mesh_node_sim mesh_protocol_stack multipath_routing network_coding network_orchestrator network_simulator olsr_routing pattern_predictor performance_benchmarks performance_profiler power_monitoring production_deployment production_scenarios quarantine_manager resource_scheduler swarm_coordinator test_framework timing_closure topology_visualizer traffic_animator failure_predictor hardware_validation integration_framework network_analytics packet_loss_injection test_validator; do
$T27C gen-c specs/${spec}.t27 > /tmp/${spec}_regen.c
if ! diff -u gen/c/${spec}.c /tmp/${spec}_regen.c; then
echo "::error file=gen/c/${spec}.c::DRIFT: gen/c/${spec}.c != t27c gen-c specs/${spec}.t27"
echo "Fix: t27c gen-c specs/${spec}.t27 > gen/c/${spec}.c"
STATUS=1
else
echo "gen/c/${spec}.c matches specs/${spec}.t27"
fi
done
exit $STATUS
cargo build --all-targets --verbose
cargo test --verbose
4 changes: 4 additions & 0 deletions .t27c-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Pinned t27c compiler — verified fix commit (optimizer removal #1456 + array/index codegen #1457).
# gen/rust must be byte-identical to `t27c gen-rust` from this exact commit.
# repo: https://github.com/gHashTag/t27 branch: fix/faithful-rust-c-codegen-1455
d7f3a73
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,16 +85,18 @@ BitNet-ternary benchmark on returned silicon, publish the raw log.
| M1 static binary size (armv7l musleabihf) | 534 604 B | `smoke/M1_RESULTS.md` |
| M1 binary sha256 | `e5abc335…7290a` | `smoke/M1_RESULTS.md` |
| M1 host tests | 20 unit + 2 integration, RC=0 | `cargo test` |
| Rust `#[test]` blocks in repo | 110 | `grep -rE '^\s*#\[test\]' src tests` |
| Rust source lines | 4 463 | `find src -name '*.rs' \| xargs wc -l` |
| Rust `#[test]` blocks in repo | 101 (all in `src/`; `tests/` dir removed 2026-07-07) | `grep -rE '^\s*#\[test\]' src` |
| Rust source lines | 4 544 | `find src -name '*.rs' \| xargs wc -l` |
| AD9361 tune target | LO 5.8 GHz | `radio/README.md` |
| AD9361 FFT peak (1 MHz tone, digital loopback) | +0.999 MHz | `radio/README.md` |
| AD9361 SNR over noise floor | 108.6 dB (digital loopback only, not over-the-air) | `radio/README.md`; see [W7 finding #5](docs/W7_WEAK_POINTS_STRUCTURAL.md#находка-5) and [REGULATORY_STATUS](docs/REGULATORY_STATUS.md) |
| AD9361 SNR over noise floor | 108.6 dB (digital loopback only, not over-the-air) | `radio/README.md`; see [W7 finding #5](docs/archive/W7_WEAK_POINTS_STRUCTURAL.md#находка-5) and [REGULATORY_STATUS](docs/REGULATORY_STATUS.md) |
| AD9361 tuning range | 70 MHz … 6 GHz | `radio/README.md` |
| Sample rate | 30.72 MHz | `radio/README.md` |
| Capture length | 65 536 samples | `radio/README.md` |

> Примечание (2026-07-10): файл `radio/README.md` удалён при уборке 2026-07-07; строки AD9361 выше — исторический digital-loopback снимок. Текущее воспроизводимое RF-доказательство: [`docs/W12_E2E_RF_TEST_RESULTS.md`](docs/W12_E2E_RF_TEST_RESULTS.md) (30/30 PASS). Не over-the-air.
| Connected P203 Mini boards | 3 | User confirmation 2026-07-04 |
| T27 spec files ported | 1 (`specs/wire.t27`) | `find specs -name '*.t27'` |
| T27 specs in tree / wired into src | 68 / 1 (`specs/wire.t27`) | `find specs -name '*.t27' \| wc -l` |

### DePIN tokenomics (contract source, `gHashTag/trinity-contracts`, not yet deployed to mainnet)

Expand Down Expand Up @@ -134,7 +136,7 @@ BitNet-ternary benchmark on returned silicon, publish the raw log.
## Build & test (host)

```bash
cargo test # 20+ unit + 2 integration tests (см. Metrics — 110 test blocks в проекте)
cargo test # 101 #[test] blocks, все в src/ (см. Metrics)
cargo run --bin smoke-m1
```

Expand Down Expand Up @@ -223,11 +225,11 @@ Sister-репозитории: [`gHashTag/t27`](https://github.com/gHashTag/t27)
## Key docs

- [`docs/LOCAL_FLASH.md`](docs/LOCAL_FLASH.md) — пошаговая локальная прошивка трёх плат.
- [`docs/WAVE_DEPIN_2026-07-04.md`](docs/WAVE_DEPIN_2026-07-04.md) — DePIN whitepaper (четыре плеча, tokenomics, positioning).
- `docs/WAVE_DEPIN_2026-07-04.md` — DePIN whitepaper (в неслитом PR #29, не на `main`).
- `docs/COMPETITOR_MATRIX_2026-07-04.md` — 10 MANET-конкурентов × 15 полей (в [PR #28](https://github.com/gHashTag/tri-net/pull/28)).
- [`docs/_recon/DEPIN_COMPETITORS_2026-07-04.md`](docs/_recon/DEPIN_COMPETITORS_2026-07-04.md) — 12 DePIN-сетей × 12 полей.
- [`docs/WAVE_N3_AUDITABILITY_GAP_2026-07-04.md`](docs/WAVE_N3_AUDITABILITY_GAP_2026-07-04.md) — auditability δ paper.
- [`docs/STRENGTHEN.md`](docs/STRENGTHEN.md) — science-driven backlog.
- `docs/_recon/DEPIN_COMPETITORS_2026-07-04.md` — 12 DePIN-сетей × 12 полей (в неслитом PR #29, не на `main`).
- [`docs/archive/WAVE_N3_AUDITABILITY_GAP_2026-07-04.md`](docs/archive/WAVE_N3_AUDITABILITY_GAP_2026-07-04.md) — auditability δ paper.
- [`docs/archive/STRENGTHEN.md`](docs/archive/STRENGTHEN.md) — science-driven backlog.
- [`docs/AUTONOMOUS.md`](docs/AUTONOMOUS.md) — human-merge only policy для agent PR's.

## License
Expand Down
12 changes: 8 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@ fn main() {
let gen_path = gen_dir.join(format!("{}.rs", name.to_str().unwrap()));

let needs_regen = !gen_path.exists() || {
let spec_time = entry.metadata().map_or(0, |m| m.modified().ok())
.map_or(0, |t| t.elapsed().map_or(0, |d| d.as_secs()));
let gen_time = std::fs::metadata(&gen_path).map_or(0, |m| m.modified().ok())
.map_or(0, |t| t.elapsed().map_or(0, |d| d.as_secs()));
let spec_time = entry.metadata().ok()
.and_then(|m| m.modified().ok())
.and_then(|t| t.elapsed().ok())
.map_or(0, |d| d.as_secs());
let gen_time = std::fs::metadata(&gen_path).ok()
.and_then(|m| m.modified().ok())
.and_then(|t| t.elapsed().ok())
.map_or(0, |d| d.as_secs());
spec_time < gen_time // spec is newer
};

Expand Down
77 changes: 77 additions & 0 deletions docs/PIPELINE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
# The golden pipeline — the ONLY correct way to change this repo

`specs/*.t27` -> `t27c gen-rust` -> `gen/rust/*.rs` -> used by `src/`

Anchor: phi^2 + phi^-2 = 3.

## Hard rules (physically enforced — see "Enforcement" below)

1. Logic is written in `.t27` specs. Never hand-write Rust in `gen/`.
2. `gen/rust/*.rs` is GENERATED ONLY, by the pinned compiler in `.t27c-version`.
It must be byte-identical to `t27c gen-rust <spec>` from that exact commit.
3. To change generated behaviour: edit the `.t27` spec, regenerate, commit both.
4. Never push to `main` directly. All changes land through a pull request whose
checks pass. (`main` is a protected branch; direct pushes are rejected.)
5. Bump `.t27c-version` only together with a full regen of `gen/rust` in the
same commit.

## Regenerate locally

```bash
# 1. Build the pinned t27c
SHA=$(grep -oE '[0-9a-f]{40}' .t27c-version | head -1)
git clone https://github.com/gHashTag/t27 ../t27 && git -C ../t27 checkout "$SHA"
cargo build --release -p t27c --manifest-path ../t27/Cargo.toml

# 2. Regenerate every module from its spec
for spec in specs/*.t27; do
n=$(basename "$spec" .t27)
../t27/target/release/t27c gen-rust "$spec" > "gen/rust/$n.rs"
done

# 3. Verify nothing drifted, then build/test
git diff --exit-code -- gen/rust/
cargo build --all-targets && cargo test
```

`build.rs` performs the same regeneration automatically when the pinned t27c is
present at `../t27/target/release/t27c`.

## Enforcement (what makes the wrong way physically impossible)

- `.github/workflows/spec-drift-guard.yml` rebuilds t27c at the pinned commit,
regenerates all `gen/rust`, and FAILS the build on any byte drift, then
builds + tests. Catches: stale/wrong compiler, hand-edited gen, spec edited
without regen.
- `.github/workflows/ci.yml` runs fmt + clippy (`-D warnings`) + build + test +
`cargo-audit`.
- Branch protection on `main`: no direct pushes, PR required, required status
checks must pass, no bypass. This is what would have stopped the 2026-07-07
breakage (a direct push of gen/rust built by a stale t27c).
- `lefthook.yml` pre-commit hooks are a local first line (no gen/ edits, no
hand-written logic in `src/`, ASCII-only) but hooks are bypassable, so CI +
branch protection are the real guard.

## t27c codegen fixes applied (pinned commit d7f3a73)

The pinned t27c carries, in order: the dropped-`let` lexer fix (t27#1401), the
`ExprCast` fix (t27#1320), the **optimizer removal for the Rust/C source
backends** (t27#1456 — the AST optimizer was dropping reassigned mutable locals
and const-inlining `let`), and the **array/index codegen fix** (t27#1457 —
`[T; N]` -> `[T; N as usize]`, non-literal indices cast to `usize`).

With these, all 68 specs regenerate to compiling Rust. The 9 generated mesh
modules (`adaptive_routing`, `multipath_routing`, `anomaly_detector`,
`flow_control`, `frame_buffer`, `health_dashboard`, `mesh_routing`, `etx`,
`quarantine_manager`) are now WIRED in `src/lib.rs`. They still have zero call
sites, so each `mod` declaration carries `#[allow(dead_code, unused,
unused_parens, clippy::all)]` for lint hygiene on generated theater.

Genuine SOURCE-spec bugs surfaced by the now-correct codegen were fixed in the
`.t27` specs (see gHashTag/tri-net#61): a `path_valid` typo, an
`is_multipath_viable` bool-vs-u32 return type, an `etx` Q8.8 `256`-in-u8 literal,
and ~50 reassigned locals switched from `let` to the mutable idiom `var`.

The pin is `d7f3a73` on branch `fix/faithful-rust-c-codegen-1455`; once
t27 PR #1456 merges to master, bump `.t27c-version` to the master SHA (the
generated output is identical).
Loading
Loading