@davoodmehraban89 / VELYQOR / commits / 3c1d019
Fork 0

Intelligence, Advanced Charting & Trading Platform

safety: merge P0 safety gates and project checkpoint (#25)

* docs(security): archive verified P0 triage and hold decisions * safety(p0): add non-destructive review gate for Navasan and order policy * safety(p0): add non-destructive review gate for Navasan and order policy * safety(p0): add non-destructive review gate for Navasan and order policy * docs(security): define P0 acceptance and release hold gates * docs(security): correct inline code formatting in release gates * docs(project): record current PR CI outcomes, dependencies, and release holds * docs(state): add verified Oct 14 P0 review checkpoint and next gates

davoodmehraban89 committed Oct 14, 2026 at 22:35 UTC 3c1d019d88f37bc61974fd522052dfb67f203b87
7 files changed +318
.github/workflows/p0-safety.yml new
+22
@@ -0,0 +1,22 @@
1 +name: P0 safety (review branch)
2 +
3 +on:
4 + pull_request:
5 + workflow_dispatch:
6 +
7 +permissions:
8 + contents: read
9 +
10 +jobs:
11 + static-guard:
12 + runs-on: ubuntu-latest
13 + timeout-minutes: 5
14 + steps:
15 + - uses: actions/checkout@v4
16 + - uses: actions/setup-node@v4
17 + with:
18 + node-version: '20'
19 + - name: Test safety guard
20 + run: node --test scripts/check-p0-safety.test.mjs
21 + - name: Enforce P0 static guard
22 + run: node scripts/check-p0-safety.mjs
PROJECT_STATE.md
+19
@@ -2,6 +2,25 @@
2
3 Last updated: 2026-10-07
4
5 +Last checked (GitHub-only): 2026-10-14
6 +
7 +> **IMPORTANT — review-branch status overlay (not yet merged into main).** The detailed sections below preserve the 2026-10-07 Phase-1 baseline. Its claims about disconnected provider keys and CI do **not** reflect a 2026-10-14 live runtime revalidation. Cloudflare previously exposed a `NAVASAN_API_KEY` secret name (not a verified end-to-end data proof); the current connected secret values were not read.
8 +
9 +## Current safety checkpoint — 2026-10-14
10 +
11 +- Working source of truth remains `main` at `29a45cff094658c7a2722fa6fa712bef061abb8c` until explicitly merged; review branch: `safety/p0-triage-2026-10-13`.
12 +- Open PRs [#21](https://github.com/davoodmehraban89/VELYQOR/pull/21), [#22](https://github.com/davoodmehraban89/VELYQOR/pull/22), [#23](https://github.com/davoodmehraban89/VELYQOR/pull/23), [#24](https://github.com/davoodmehraban89/VELYQOR/pull/24), [#25](https://github.com/davoodmehraban89/VELYQOR/pull/25), and [#26](https://github.com/davoodmehraban89/VELYQOR/pull/26). PR #23 is based on the history feature branch; PR #24 is based on #23. PR #25 and #26 are isolated reviews from `main`.
13 +- GitHub CI: #21, #22, #23 succeeded on second attempts 2026-10-14; #24 succeeded on its latest verified attempt 2026-10-12; #25 and #26 succeeded on 2026-10-14. A green CI does **not** establish data licensing, provider uptime, a real production Neon→Worker connection, or deployed streaming.
14 +- **P0 PROTECT:** last verified Windows evidence included 9 tracked modifications, 1085 untracked paths and 5 worktrees. Desktop Commander was offline on 2026-10-14. No cleaning, overwriting or migration applied.
15 +- **P0 BLOCK_IMPORT:** untracked `db/migrations/0005_navasan_private_daily_ohlc.sql` conflicts with existing adapter IRR→IRT assumptions. No import or migration before source-confirmed units/quote side, rights and reviewed dry-run.
16 +- **P0 BLOCK_REDISTRIBUTION:** commercial source-OHLC storage and public redistribution rights remain unverified. ECB observations are reference points, not OHLC candles.
17 +- **P0 NO_LIVE_ORDERS:** AI/signals cannot place live orders; independent order/risk controls and separate approval are required before any trading layer.
18 +- Next actions: review independent #21/#22/#25/#26 for prospective merges; preserve #23/#24 as Draft until dependency, license, Neon reader, staging and end-to-end gates pass; verify Windows and provider documentation when available.
19 +- Auditable details and ownership: [P0 triage](docs/security/P0_TRIAGE_2026-10-12_FA.md), [release safety gates](docs/security/P0_RELEASE_GATES.md), [PR readiness](docs/security/PR_READINESS_2026-10-14_FA.md).
20 +- **Status of this checkpoint:** documentation and CI pass on review branches; **no merge to `main`, no operational deployment, no credential changes, no trade**.
21 +
22 +---
23 +
24 ## Current phase
25 Phase 1 — Market Data Integrity & Data Proof.
26
docs/security/P0_RELEASE_GATES.md new
+37
@@ -0,0 +1,37 @@
1 +# VELYQOR — P0 Safety and Release Gates
2 +
3 +**Recorded:** 2026-10-13
4 +**Status:** HOLD for production changes; review-branch guard only.
5 +**Parent:** `main` at `29a45cff094658c7a2722fa6fa712bef061abb8c`.
6 +**Evidence:** [P0 execution and decision record](./P0_TRIAGE_2026-10-12_FA.md).
7 +
8 +## Scope and ownership
9 +
10 +This branch is a non-production review checkpoint. It MUST NOT be considered approval to merge another branch, run `db/migrations/0005_navasan_private_daily_ohlc.sql`, activate a provider, deploy a Worker or place a trade. Do not rewrite a dirty local worktree. Only the project owner can approve a scope-expanding action, and financial/credential/billable actions need separate explicit authorization.
11 +
12 +| Gate | Default | Owner | Evidence needed before release |
13 +|---|---|---|---|
14 +| Local dirty worktrees | PROTECT | Project coordinator | Owner inventory; verified backup/snapshot procedure, no reset/clean/stash/overwrite without consent |
15 +| Navasan `ohlcSearch` units/quote side | BLOCK IMPORT | Market Data & Quant + DB | Vendor-confirmed per-symbol IRR/IRT, bid/ask and time contract; actual sanitized payload; unit-factor tests; reviewed transactional dry run and rollback |
16 +| Commercial OHLC storage/public redisplay | BLOCK | Product/Legal + Data | Verified contract rights by provider, market, use case, attribution, retention and redistribution; private contract stored outside public GitHub |
17 +| AI/signals to real orders | PROHIBITED | Security + Trading | Separate approved order/risk architecture, permissions, idempotency, limits, kill switch, negative integration tests and explicit launch approval |
18 +| Phase 1 live-data proof | OPEN | QA + Market Data | Continuous measured cadence/freshness/gaps/duplicates/outage recovery and realistic alerting |
19 +| Branch acceptance/deployment | HOLD | QA/Release | Relevant green CI, unit/integration/E2E security tests, live authorization, rollback evidence and owner's separate release approval |
20 +
21 +## Automated check included on this branch
22 +
23 +- `node --test scripts/check-p0-safety.test.mjs`
24 +- `node scripts/check-p0-safety.mjs`
25 +- `.github/workflows/p0-safety.yml` runs the checks on a pull request or when manually dispatched on an eligible ref. It does **not** deploy, access live databases, read credentials or submit orders.
26 +- The guard rejects a proposed `0005` migration or migrations containing the current Navasan OHLC source markers. It also detects drift of the current unit assumptions and the explicit no-AI-order rule.
27 +- A green guard is only a **static repository-level check**: it is NOT proof of provider licensing, correctness of external prices, complete absence of order-execution code, runtime permission hardening or production readiness.
28 +- After genuine evidence and owner review, modify the static guard **in the same reviewed change** as the approved migration; do not disable it silently.
29 +- This workflow exists only on this isolated branch at present and **is not an enforced required check for `main`**. Branch protection and merging are separate owner-approved tasks.
30 +
31 +## Immediate follow-up
32 +
33 +1. Preserve all 5 Windows worktrees and the known untracked `0005` migration. Do not automatically sync this branch into that device.
34 +2. Obtain direct Navasan commercial/OHLC unit and redistribution evidence outside public GitHub.
35 +3. Once remote device access returns, rerun the full domain test suite from the repository root and compare tracked/untracked status before/after.
36 +4. Review PR #21–#24 with their actual base dependencies, keeping PR #23 and #24 draft until runtime, licensing and security gates clear.
37 +5. Do not perform migrations, Cloudflare deployment, credential/role updates or real trading as part of this branch.
docs/security/P0_TRIAGE_2026-10-12_FA.md new
+88
@@ -0,0 +1,88 @@
1 +> **یادداشت آرشیو (۱۳ اکتبر ۲۰۲۶):** وضعیت‌ها و عبارات «هنوز به GitHub منتقل نشده» در متن زیر مربوط به زمان ثبت اولیه سند (۱۲ اکتبر) هستند. این نسخه در شاخه مستقل `safety/p0-triage-2026-10-13` ثبت می‌شود؛ هیچ تغییری در محیط محلی یا Production انجام نمی‌شود.
2 +
3 +# VELYQOR — P0 Execution & Decision Record
4 +
5 +**تاریخ مبنا:** ۱۲ اکتبر ۲۰۲۶
6 +**مأموریت:** تعیین تکلیف اقدامات حیاتی بدون حذف تغییرات محلی، دسترسی حساس، استقرار عمومی یا معامله واقعی
7 +**وضعیت سند:** خروجی ممیزی مستقلِ این گفت‌وگو؛ **هنوز به GitHub یا دیسک رایانه کاربر Commit/Sync نشده است**.
8 +
9 +## منابع حقیقت
10 +
11 +- مخزن: https://github.com/davoodmehraban89/VELYQOR
12 +- `main`: `29a45cff094658c7a2722fa6fa712bef061abb8c`
13 +- شاخه محلی فعال: `feature/chartnova-neon-history`، SHA: `213b6821f5d732ff94e11e2b9ba481cbd49b4591`
14 +- مسیر: `C:\Users\Davood\Documents\VELYQOR`
15 +- PR #23: https://github.com/davoodmehraban89/VELYQOR/pull/23
16 +- PR #24: https://github.com/davoodmehraban89/VELYQOR/pull/24
17 +- CI موفق PR #24 (تلاش دوم): https://github.com/davoodmehraban89/VELYQOR/actions/runs/38203704482
18 +- راهنمای رسمی Navasan: https://www.navasan.tech/webserviceguide/ و https://www.navasan.tech/en/api
19 +
20 +## P0-01 — حفاظت از تغییرات محلی
21 +
22 +**تصمیم:** HOLD/PROTECT؛ هیچ `git reset`, `git clean`, `checkout`, `merge`, `stash`, حذف فایل یا بازنویسی Worktree مجاز نیست تا وضعیت مالکیت تغییرات روشن شود.
23 +
24 +**شواهد دوباره‌بررسی‌شده:**
25 +- ۹ فایل رهگیری‌شده تغییرکرده در Worktree اصلی: `AGENTS.md`, `PROJECT_STATE.md`, `README.md`, `docs/architecture/ADR-0001-foundation.md`, `ADR-0002-postgresql-provider-portability.md`, `ADR-0003-managed-postgres-hosting.md`, `docs/data/market-contracts.md`, `docs/data/phase1-live-postgres-proof.md`, `package.json`.
26 +- ۱۰۸۵ مسیر Untracked در Worktree اصلی؛ اکثر آن‌ها داخل `artifacts/` هستند، ولی `db/migrations/0005_navasan_private_daily_ohlc.sql` هم Untracked است.
27 +- چهار Worktree آزمایشی دیگر به ترتیب ۳، ۱، ۴ و ۰ مسیر Untracked داشتند و در خروجی `status -uno` فایل رهگیری‌شده تغییری دیده نشد.
28 +- SHA256 فایل Migration غیرمتعهد: `674CE00898419BECF3652323E05D4821064E88E0B3FBB6B650578BB63134F171`.
29 +- `.env.local` توسط Git ignore شده و محتویات حساس آن خوانده نشد.
30 +
31 +**تکمیل‌شده:** شناسایی تغییرات و تثبیت قانون حفاظت. **انجام‌نشده:** تأیید مالکیت فایل‌های ثبت‌نشده/گرفتن Snapshot امن و پاک‌سازی؛ هیچ پاک‌سازی لازم یا مجاز اعلام نشده است.
32 +
33 +## P0-02 — اختلاف IRR / IRT در Navasan
34 +
35 +**تصمیم:** `BLOCK_IMPORT`؛ Migration `0005` و هیچ داده Navasan OHLC در Production اجرا یا وارد نشود مگر قرارداد واحد/Quote Side منبع با شواهد مستقل تأیید شود. صرف اندازه عدد قیمت برای انتخاب واحد کافی نیست.
36 +
37 +**شواهد:**
38 +- Adapter در `packages/market-domain/src/adapters/navasan.mjs` به‌طور صریح `IRR_PER_USD` و `IRR_PER_GRAM` را به IRT با تقسیم بر ۱۰ تبدیل می‌کند.
39 +- Migration محلی در `provider_instruments.metadata` برای هر دو نماد `raw_unit='IRT'` قرار داده و در Audit Table واحدهای `IRT_PER_USD/IRT_PER_GRAM` تعریف کرده است.
40 +- راهنمای انگلیسی Navasan API را با داده IRR معرفی می‌کند، اما مجوز و قرارداد قطعی **برای Payload ویژه endpoint `ohlcSearch` و تک‌تک نمادها** از مستند بررسی‌شده به‌قدر کافی ثابت نشده است؛ نمونهٔ پلاگین سایت نیز قیمت را به تومان نمایش می‌دهد. فرض Unit از شدت/اندازهٔ قیمت ممنوع است.
41 +- هشت تست محلی محدود به Adapter و OHLC با موفقیت گذشت؛ این تست‌ها فرض موجود IRR را می‌آزمایند، نه حقیقت تجاری/واحد داده زنده.
42 +- Neon مستقیماً بررسی شد: `candle_source_provenance` وجود ندارد، نمای `chartnova_navasan_candle_audit` وجود ندارد، Provider با کد `navasan_ohlc` ندارد و `candles=0`. بنابراین Migration شماره 0005 در این پایگاه اجرا نشده است.
43 +
44 +**معیار رفع انسداد:** مستند معتبر Vendor + نمونه واقعی با Timestamp، نماد، Unit، Quote Side، حقوق استفاده، نسخه قرارداد، سپس تست اختلاف ضریب ۱۰ و Dry-run تراکنشی با Rollback. **در غیر این‌صورت HOLD باقی بماند.**
45 +
46 +## P0-03 — مجوز تجاری داده OHLC
47 +
48 +**تصمیم:** `BLOCK_PUBLIC_REDISTRIBUTION` و `BLOCK_UNLICENSED_INGESTION`.
49 +
50 +API عمومی `ohlcSearch` و اطلاعات پلن به‌خودی‌خود مجوز ذخیره/بازنشر تجاری و راه‌اندازی سرویس عمومی نیست. Validator شاخه PR #23 ورودی License Manifest را بررسی می‌کند، اما اثبات اصالت قرارداد توسط انسان/تأیید حقوقی لازم است. داده‌های ECB (۷۶۲ نقطه) Reference Point هستند و به `candles` منتقل نمی‌شوند.
51 +
52 +**معیار رفع انسداد:** سند مجوز با حق نگهداری، استفاده تجاری، بازنمایش عمومی، مشتقات، نگهداری تاریخچه و Attribution برای هر Provider؛ نگهداری اصل قرارداد خارج از مخزن عمومی و صرفاً Evidence Reference بدون اطلاعات حساس داخل مخزن.
53 +
54 +## P0-04 — کنترل معاملات واقعی و AI
55 +
56 +**تصمیم:** `NO_LIVE_ORDERS` تا تصویب رسمی لایه مستقل Risk/Order Management و اجرای Negative Tests. سیاست در `AGENTS.md` وجود دارد: سیگنال/AI نباید مستقیماً سفارش صادر کند.
57 +
58 +**شواهد محدود:** بررسی نام فایل‌های درخت کامل PR #24 (۱۲۸ فایل) هیچ ماژول مربوط به Order/Trade/Execution شناسایی نکرد و بررسی Worker منتخب تنها مسیرهای `/stream` و `/internal/market-update` را نشان داد؛ الگوی مستقیم ثبت سفارش در همان Worker یافت نشد. این ممیزی جایگزین Pen Test یا بررسی محیط‌های خارجی نیست.
59 +
60 +**معیار پذیرش آینده:** RBAC، تفکیک اختیار، Kill Switch، Paper Trading، سقف ریسک، Idempotency و آزمون مجوزهای منفی پیش از فعال‌سازی Exchange Order API. خارج از MVP اولیه مصوب باقی بماند تا محصول تصمیم بگیرد.
61 +
62 +## نتیجه آزمون‌ها و CI
63 +
64 +- تست محلی محدود Navasan: **۸ از ۸ PASS**.
65 +- تلاش اجرای کل تست‌های دامنه روی Windows از مسیر اشتباه `cwd`، **۶۸ PASS / ۱ FAIL** ثبت کرد؛ آزمون شکست‌خورده فقط نتوانست `scripts/phase1-live-data-proof.mjs` را از مسیر اشتباه Desktop Commander پیدا کند (`MODULE_NOT_FOUND`). شواهد فعلی این را خطای محل اجرای فرمان نشان می‌دهند، نه نقص ثابت‌شده الگوریتم. باید از ریشه مخزن دوباره اجرا شود.
66 +- تلاش برای اجرای مجدد از ریشه مخزن به‌دلیل اتمام سهمیه Desktop Commander مقدور نشد؛ **نتیجه کامل محلی را PASS اعلام نکن**.
67 +- مستقل از اجرای محلی، GitHub Actions روی HEAD فعلی PR #24 در تلاش دوم، `verify` و `postgres-invariants` را با گام‌های واقعی موفق اعلام کرده است. این صرفاً گیت CI همان Commit است، نه مجوز انتشار عمومی یا اتصال Providerها.
68 +
69 +## وضعیت اقدامات عملیاتی
70 +
71 +| اقدام | نتیجه | مالک مرحله بعد |
72 +|---|---|---|
73 +| شناسایی و حفاظت از Dirty Worktrees | تصمیم حفاظتی ثبت شد؛ فایل‌ها دست‌نخورده | هماهنگ‌کننده/مالک Worktree |
74 +| جلوگیری از Migration مبهم | عدم اجرا در Neon مستقیماً اثبات شد؛ HOLD منطقی مقرر | Data & Quant / DB |
75 +| مجوز OHLC | مجوز تجاری اثبات نشده؛ Gate مسدودکننده ثبت شد | Product/Legal + Data |
76 +| اجرای AI-to-Order | در دامنه بررسی‌شده ماژول عملیاتی دیده نشد؛ NO-LIVE-ORDERS | Security/Trading |
77 +| تست یکپارچه محلی | به‌علت خطای CWD و سهمیه Remote ناقص | QA |
78 +| آخرین PR #24 CI | موفق | QA |
79 +
80 +## اولین گام بعدی (بدون تغییر پرریسک)
81 +
82 +۱. با بازگشت سهمیه Desktop Commander، از ریشه Worktree اصلی `node --test packages/market-domain/test/*.test.mjs` اجرا و Status بعد از تست با قبل مقایسه شود.
83 +۲. از ارائه‌دهنده Navasan به‌صورت رسمی Unit/Quote Side و حقوق تجاری `ohlcSearch` برای `usd_sell` و `18ayar` دریافت شود.
84 +۳. تا زمان احراز دو بند قبل، Migration 0005 و Import عمومی را فعال نکنید.
85 +۴. هنگام پذیرش PRهای #23 و #24 ابتدا وابستگی شاخه، تست‌های زنده و Rollback بررسی شوند.
86 +۵. اگر قرار است این سند به مخزن عمومی GitHub افزوده شود، برای آن مجوز مشخص انتشار و مسیر Branch مستقل دریافت شود.
87 +
88 +**هیچ تغییر در GitHub، Neon، Cloudflare، Worktreeهای رایانه یا سفارش معاملاتی طی این اجرای P0 انجام نشده است.**
\ No newline at end of file
docs/security/PR_READINESS_2026-10-14_FA.md new
+42
@@ -0,0 +1,42 @@
1 +# VELYQOR — فهرست پذیرش PR و موانع انتشار
2 +
3 +**تاریخ بررسی:** ۱۴ اکتبر ۲۰۲۶
4 +**محدوده:** بررسی خواندنی GitHub و نتایج واقعی CI. هیچ ادغام یا استقرار انجام نشده است.
5 +**مسئول اصلی:** هماهنگ‌کننده پروژه؛ بررسی فنی توسط حوزه QA/Release و ایمنی بازار داده.
6 +
7 +## مبنای قابل‌ردیابی
8 +
9 +- `main`: `29a45cff094658c7a2722fa6fa712bef061abb8c`
10 +- آخرین ممیزی Windows در ۱۲ اکتبر: Worktree اصلی دارای ۹ فایل ویرایش‌شده و ۱۰۸۵ مسیر ثبت‌نشده بود. چهار Worktree آزمایشی دیگر نیز وجود داشتند. در بررسی ۱۴ اکتبر Desktop Commander آفلاین بود؛ **وضعیت محلی مجدداً کنترل نشده است**.
11 +- Neon در آخرین بررسی تأییدشده: ۷۶۲ Reference Point مربوط به ECB، صفر Candle واقعی، و Migration شماره 0005 اعمال نشده است. این اعداد اسنپ‌شات تاریخی هستند، نه وضعیت لحظه‌ای ۱۴ اکتبر.
12 +
13 +## جدول تصمیم درباره PRهای باز
14 +
15 +| PR | آخرین وضعیت CI | وابستگی | تصمیم / معیار پذیرش |
16 +|---|---|---|---|
17 +| [#21](https://github.com/davoodmehraban89/VELYQOR/pull/21) | سبز؛ rerun دوم ۱۴ اکتبر | `main` | اصلاح Parser پاسخ Alpha Vantage؛ قبل از ادغام بازبینی کد و آزمون Negative Unit/Time؛ اثبات تازگی دائمی از CI قابل استنتاج نیست |
18 +| [#22](https://github.com/davoodmehraban89/VELYQOR/pull/22) | سبز؛ rerun دوم ۱۴ اکتبر | `main` | Candidate Gold API؛ پذیرش کد از پذیرش Provider عملیاتی جدا باشد؛ Data Proof پیوسته، مجوز و محدودیت سهمیه لازم است |
19 +| [#23](https://github.com/davoodmehraban89/VELYQOR/pull/23) | سبز؛ rerun دوم ۱۴ اکتبر | `feature/chartnova-neon-history` | Draft بماند؛ اتصال امن واقعی Neon Reader و اثبات حق OHLC/قوانین Gate لازم است؛ وابستگی Base باید قبل از ادغام مدیریت شود |
20 +| [#24](https://github.com/davoodmehraban89/VELYQOR/pull/24) | سبز؛ rerun دوم ۱۲ اکتبر | `feature/chartnova-neon-direct-history` (PR #23) | Draft بماند؛ UI/WS فقط اسکلت تست‌شده است، نه Feeds عملیاتی؛ Staging، Publisher، Entitlement و ریسک انتشار باید مستقل تصویب شوند |
21 +| [#25](https://github.com/davoodmehraban89/VELYQOR/pull/25) | سبز؛ `static-guard`، `verify` و `postgres-invariants` در ۱۴ اکتبر | `main` | Draft؛ کنترل فقط‌خواندنی P0 را پیشنهاد می‌کند؛ هنوز Required Check روی `main` نیست؛ بازبینی مالک پروژه قبل از Merge |
22 +| [#26](https://github.com/davoodmehraban89/VELYQOR/pull/26) | سبز؛ `verify` و `postgres-invariants` در ۱۴ اکتبر | `main` | Draft؛ ایراد CWD در آزمون نبود Credentials اصلاح شد؛ رگرسیون مستقل ویندوز به‌علت آفلاین‌بودن دستگاه باقی است |
23 +
24 +## مسیر بدون توقف
25 +
26 +1. کدهای مستقل #21، #22 و #26 قابل بازبینی و تصمیم Merge هستند؛ موفقیت CI فقط پذیرش فنی اولیه است، نه تأیید بهره‌برداری منبع داده.
27 +2. #25 باید برای ادغام حفاظتی مستقلاً بازبینی شود؛ پس از Merge و پیکربندی Required Check، حفاظت تغییرات آینده قوی‌تر می‌شود. اعمال Rule/Branch Protection به مجوز مشخص دسترسی نیاز دارد.
28 +3. #23 و #24 وابستگی زنجیره‌ای دارند. ترتیب منطقی: ابتدا تعیین‌تکلیف Base #23، سپس #24. بدون Neon Credential با حداقل مجوز و تست End-to-End، ویژگی History مستقیم فعال نشود.
29 +4. دریافت مجوز رسمی نگهداری و بازنشر Navasan `ohlcSearch` و تعیین واحد واقعی `usd_sell` و `18ayar` مانع مستقل خارج از GitHub است. با نبود شواهد `0005` نباید اجرا شود.
30 +5. بازگشت اتصال Desktop Commander لازم است تا Worktree محلی، تست Windows و وضعیت Migration ثبت‌نشده واقعاً بررسی شوند. اجرای `git clean/reset/stash` بدون تصمیم مالک ممنوع است.
31 +
32 +## گیت‌های بدون استثنا
33 +
34 +- **NO LIVE ORDER:** AI یا Signal مجاز به ارسال مستقیم سفارش نیست؛ هر اتصال معاملاتی واقعی نیاز به معماری مستقل مدیریت سفارش/ریسک و تصویب صریح دارد.
35 +- **NO FABRICATED DATA:** ECB Reference Point نباید به OHLC تبدیل نمایشی شود؛ داده مفقود نباید کندل ساختگی تولید کند.
36 +- **NO UNLICENSED STORAGE/REDISTRIBUTION:** داشتن API Key، اثبات حق تجاری نیست.
37 +- **NO PRODUCTION DEPLOYMENT:** موفقیت CI برابر انتشار نیست. Neon/Cloudflare/Domain و اسرار عملیاتی در این مرحله دست‌نخورده باقی بمانند.
38 +
39 +## معیار پایان برای مرحله کنونی
40 +
41 +تکمیل شده: بازبینی مجدد شش PR، شناسایی مانع‌های اصلی، اجرای مجدد CIهای قبلی، و ثبت گیت‌های P0 در Branch بررسی.
42 +تکمیل نشده: ادغام، اجرای تست مستقل Windows، تأیید حقوقی داده، اثبات Feed زنده، استقرار ایمن؛ این کارها نباید «Done» شوند.
scripts/check-p0-safety.mjs new
+57
@@ -0,0 +1,57 @@
1 +// P0 repository guard: static, read-only and deliberately fail-closed.
2 +// Not a legal-license validation, runtime security audit or production deployment gate.
3 +import { readFile, readdir } from 'node:fs/promises';
4 +import { dirname, join, resolve } from 'node:path';
5 +import { fileURLToPath } from 'node:url';
6 +
7 +const ownRoot = resolve(dirname(fileURLToPath(import.meta.url)), '..');
8 +const MIGRATION_BLOCK_PATTERN = /navasan_ohlc|ohlcSearch|candle_source_provenance|chartnova_navasan_candle_audit/i;
9 +
10 +export async function evaluateP0Safety(root = ownRoot) {
11 + const violations = [];
12 + const migrationDir = join(root, 'db', 'migrations');
13 + let migrations;
14 + try {
15 + migrations = (await readdir(migrationDir)).filter((name) => name.endsWith('.sql'));
16 + } catch {
17 + return { ok: false, violations: ['Cannot enumerate db/migrations; safety review required.'] };
18 + }
19 + for (const filename of migrations) {
20 + const contents = await readFile(join(migrationDir, filename), 'utf8');
21 + if (filename === '0005_navasan_private_daily_ohlc.sql' || MIGRATION_BLOCK_PATTERN.test(contents)) {
22 + violations.push(filename + ': Navasan/OHLC migration HOLD; verify exact units, quote-side, license, provenance and review before changing this guard.');
23 + }
24 + }
25 +
26 + try {
27 + const adapter = await readFile(join(root, 'packages', 'market-domain', 'src', 'adapters', 'navasan.mjs'), 'utf8');
28 + if (!/rawUnit:\s*['"]IRR_PER_USD['"]/.test(adapter) || !/rawUnit:\s*['"]IRR_PER_GRAM['"]/.test(adapter)) {
29 + violations.push('Navasan adapter raw-unit contract changed; manual unit/quote-side review required.');
30 + }
31 + } catch {
32 + violations.push('Navasan adapter missing or unreadable; manual review required.');
33 + }
34 +
35 + try {
36 + const agentRules = await readFile(join(root, 'AGENTS.md'), 'utf8');
37 + if (!/AI\/signals may never directly execute an order\./.test(agentRules)) {
38 + violations.push('AI-to-live-order prohibition in AGENTS.md changed or missing.');
39 + }
40 + } catch {
41 + violations.push('AGENTS.md missing or unreadable; manual review required.');
42 + }
43 +
44 + return { ok: violations.length === 0, violations };
45 +}
46 +
47 +if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
48 + const root = process.argv[2] ? resolve(process.argv[2]) : ownRoot;
49 + const outcome = await evaluateP0Safety(root);
50 + if (outcome.ok) {
51 + console.log('P0 static guard: PASS (no blocked migration detected; baseline contracts present).');
52 + } else {
53 + for (const item of outcome.violations) console.error('P0 static guard: BLOCK - ' + item);
54 + process.exitCode = 1;
55 + }
56 + console.log('Reminder: PASS does not establish market-data licensing, valid live feeds or trading safety.');
57 +}
scripts/check-p0-safety.test.mjs new
+53
@@ -0,0 +1,53 @@
1 +import test from 'node:test';
2 +import assert from 'node:assert/strict';
3 +import { mkdtemp, mkdir, writeFile, rm } from 'node:fs/promises';
4 +import { join } from 'node:path';
5 +import { tmpdir } from 'node:os';
6 +import { evaluateP0Safety } from './check-p0-safety.mjs';
7 +
8 +async function fixture() {
9 + const root = await mkdtemp(join(tmpdir(), 'velyqor-p0-'));
10 + await mkdir(join(root, 'db', 'migrations'), { recursive: true });
11 + await mkdir(join(root, 'packages', 'market-domain', 'src', 'adapters'), { recursive: true });
12 + await writeFile(join(root, 'db', 'migrations', '0001_market_core.sql'), 'CREATE TABLE harmless(id int);');
13 + await writeFile(join(root, 'packages', 'market-domain', 'src', 'adapters', 'navasan.mjs'), "rawUnit: 'IRR_PER_USD'; rawUnit: 'IRR_PER_GRAM';");
14 + await writeFile(join(root, 'AGENTS.md'), 'AI/signals may never directly execute an order.');
15 + return root;
16 +}
17 +
18 +async function withFixture(fn) {
19 + const root = await fixture();
20 + try { await fn(root); } finally { await rm(root, { recursive: true, force: true }); }
21 +}
22 +
23 +test('baseline passes without altering source files', () => withFixture(async (root) => {
24 + assert.deepEqual(await evaluateP0Safety(root), { ok: true, violations: [] });
25 +}));
26 +
27 +test('unreviewed 0005 OHLC migration is blocked', () => withFixture(async (root) => {
28 + await writeFile(join(root, 'db', 'migrations', '0005_navasan_private_daily_ohlc.sql'), 'SELECT 1;');
29 + const result = await evaluateP0Safety(root);
30 + assert.equal(result.ok, false);
31 + assert.match(result.violations.join('\n'), /0005_navasan_private_daily_ohlc/);
32 +}));
33 +
34 +test('renamed Navasan OHLC migration is blocked', () => withFixture(async (root) => {
35 + await writeFile(join(root, 'db', 'migrations', '0006_more.sql'), "INSERT INTO providers(code) VALUES ('navasan_ohlc');");
36 + assert.equal((await evaluateP0Safety(root)).ok, false);
37 +}));
38 +
39 +test('changed unit assumptions are blocked', () => withFixture(async (root) => {
40 + await writeFile(join(root, 'packages', 'market-domain', 'src', 'adapters', 'navasan.mjs'), "rawUnit: 'IRT_PER_USD'; rawUnit: 'IRT_PER_GRAM';");
41 + assert.match((await evaluateP0Safety(root)).violations.join('\n'), /raw-unit contract/);
42 +}));
43 +
44 +test('removing no-AI-order rule is blocked', () => withFixture(async (root) => {
45 + await writeFile(join(root, 'AGENTS.md'), '# Rules\n');
46 + assert.match((await evaluateP0Safety(root)).violations.join('\n'), /AI-to-live-order/);
47 +}));
48 +
49 +test('missing migration directory fails closed', async () => {
50 + const root = await mkdtemp(join(tmpdir(), 'velyqor-p0-empty-'));
51 + try { assert.equal((await evaluateP0Safety(root)).ok, false); }
52 + finally { await rm(root, { recursive: true, force: true }); }
53 +});