# GTI Discovery This project is strictly read-only. Discovery code must use a database-level read-only account or transaction/driver mode; lexical SQL validation is only defense-in-depth. Discovery code must not perform DML or DDL, modify database objects or permissions, or store credentials and other secrets. Run the offline tests with: ```text python -m pytest tests -q ``` ## Firebird write policy Default policy: - All client/production Firebird databases are STRICTLY READ-ONLY. - Never perform INSERT, UPDATE, DELETE, DDL, permission changes, or destructive operations against any client/production ERP database unless explicitly authorized in a future policy change. Explicit development exception: The following database is a disposable TEST DATABASE and is explicitly authorized for writes: ``` D:\PROJETOS\GTISISTEMAS\Projeto\TESTESOFICIAIS.FDB ``` For this exact file only, the agent MAY perform: - SELECT - INSERT - UPDATE - DELETE - DDL - transactional tests - rollback/recovery tests - destructive development experiments when necessary This database has external intact backups and can be restored. Safety requirement: Before ANY Firebird write, the code must verify that the canonical absolute database path is exactly: ``` D:\PROJETOS\GTISISTEMAS\Projeto\TESTESOFICIAIS.FDB ``` If the path differs in any way, writes must fail closed. Never infer write authorization from filename alone. Never enable writes to other Firebird databases. Secrets: - credentials remain local in ignored environment files; - never log, commit, or expose passwords. Development priority: - TESTESOFICIAIS.FDB may be modified freely as needed to validate the MVP. - Do not over-engineer rollback protections for this disposable test database unless they are part of the product behavior being validated. ## GTI Fiscal write-target rule The SGV keeps its fiscal defaults in the canonical product record (`C000025`); every other routine consumes them. GTI Fiscal therefore writes ONLY to the canonical product record, and only fields whose mapping is proven (`docs/SGV_PRODUCT_FISCAL_UI_MAP_V1.json`, `write_target=true`). It never writes to NFCE, NFCE_ITENS, item tables, issued documents or any other transactional/historical table; those are read-only evidence for validation. Company context (UF, CRT) is read from `C000004` at run time — never hardcoded. ## Local completion mission — exact write allowlist (operator-authorized) For the "GTI FISCAL LOCAL COMPLETION V1" mission the operator explicitly authorized writes to the disposable COPIES listed, by exact canonical path, in `docs/LOCAL_WRITE_ALLOWLIST_V1.json` (CONSTRUCAO, MMMODAS, RINCAO, UNIAO under `Projeto\Banco\`, plus TESTESOFICIAIS.FDB). Authorization is by exact path only — never by directory or `.FDB` extension. Any other Firebird under `D:\PROJETOS\GTISISTEMAS` stays strictly READ-ONLY. Writes go through the guarded executor (path allowlist, company-context guard, schema/type/length guard, compare-before-write, rowcount, transaction, audit) and only to `C000025` fields whose contract in `docs/FISCAL_FIELD_CONTRACT_V1.json` has `WRITE_ALLOWED=true`. This authorization does not extend to production or client databases. ## Production deploy rule (Hub) Normal deploy = `powershell -ExecutionPolicy Bypass -File .\scripts\deploy_hub.ps1 [-PublishAgent -Version X]` (docs/DEPLOY_HUB.md). Do not recreate ad-hoc deploy scripts (deploy115.py etc.) and do not improvise SSH/docker against 10.0.10.117. The script handles VPN/SSH retry, backup, upload, migrations, rebuild, health, release publish, download verification, and automatic rollback; the real error is in `logs/last_deploy_result.json` and the log.