比较提交
2 提交
b3420e485a
...
6a1eeabea8
| 作者 | SHA1 | 提交日期 | |
|---|---|---|---|
| 6a1eeabea8 | |||
| ed743422b5 |
共有 11 个文件被更改,包括 505 次插入 和 50 次删除
|
|
@ -18,6 +18,10 @@ The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and
|
||||||
- Provisional desktop-v1alpha1 Rust types, TypeScript exports, ten JSON Schemas, drift checks, and two loopback-only Mock Gateway instances.
|
- Provisional desktop-v1alpha1 Rust types, TypeScript exports, ten JSON Schemas, drift checks, and two loopback-only Mock Gateway instances.
|
||||||
- Frontend, browser, Rust, integration, Windows provider, soak, and Forgejo CI test entry points.
|
- Frontend, browser, Rust, integration, Windows provider, soak, and Forgejo CI test entry points.
|
||||||
- P00 dependency review and durable Spike result records.
|
- P00 dependency review and durable Spike result records.
|
||||||
|
- Persistent SQLite application-data initialization with transactional `user_version` migration and future-version rejection.
|
||||||
|
- Strict Zod validation for the Rust bootstrap IPC payload, including the active database schema version.
|
||||||
|
- Redacting tracing output writer with structured-field, bearer-token, URL-credential, private-key, and known-secret coverage.
|
||||||
|
- P01 migration, logging, IPC validation, real Tauri startup, and production-build verification.
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,3 +50,15 @@
|
||||||
- Implementation: the identity is configured only in this repository.
|
- Implementation: the identity is configured only in this repository.
|
||||||
- Result: two Conventional Commit baseline commits were created on `main`, pushed normally, and followed by scoped feature-branch commits.
|
- Result: two Conventional Commit baseline commits were created on `main`, pushed normally, and followed by scoped feature-branch commits.
|
||||||
- Safety impact: no global Git identity was changed.
|
- Safety impact: no global Git identity was changed.
|
||||||
|
|
||||||
|
## PD-0008: Profile CRUD stage ownership
|
||||||
|
|
||||||
|
- Status: unresolved; blocks Profile CRUD implementation only
|
||||||
|
- Conflict: `docs/01_Architecture_Design.md` lists Profile CRUD in stage 1, while `docs/02_Codex_Implementation_Tasks.md` lists ConnectionProfile CRUD in Batch 2.
|
||||||
|
- Impact: resolving this changes the database schema, Tauri IPC surface, frontend state model, and the acceptance boundary between `feat/p01-foundation` and `feat/p02-dual-connections`.
|
||||||
|
- Safe current action: complete only the unambiguous P01 foundation work<72><6B>persistent migrations, validated bootstrap IPC, redacted logging, tray, single-instance, exit flow, and tests.
|
||||||
|
- Paused work: profile tables, Profile CRUD commands, profile forms, and profile-to-slot assignment.
|
||||||
|
- Required decision:
|
||||||
|
- Option A: architecture document wins; implement basic Profile CRUD in P01 and leave slot assignment/connection behavior for P02.
|
||||||
|
- Option B: implementation task batching wins; keep all ConnectionProfile CRUD in P02.
|
||||||
|
- Recommendation: Option A is the literal higher-priority document, but the implementation remains paused because AGENTS.md requires explicit reporting for conflicts affecting database structure or public interfaces.
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
# P00 Bootstrap Implementation Plan
|
# Implementation Plan
|
||||||
|
|
||||||
|
## P00 Bootstrap (completed)
|
||||||
|
|
||||||
## Objective
|
## Objective
|
||||||
|
|
||||||
|
|
@ -30,7 +32,28 @@ Establish a reproducible Tauri 2 + React + TypeScript + Rust baseline and comple
|
||||||
|
|
||||||
- Rust/MSVC/Tauri are verified and no longer block local work.
|
- Rust/MSVC/Tauri are verified and no longer block local work.
|
||||||
- Git Credential Manager reauthentication succeeded and the non-forced HTTP push created the remote `main` baseline at `0d12b94`.
|
- Git Credential Manager reauthentication succeeded and the non-forced HTTP push created the remote `main` baseline at `0d12b94`.
|
||||||
- Development is active on `feat/p00-bootstrap`; the remaining repository handoff step is a normal push of this feature branch.
|
- Forgejo PR #1 merged P00 into `main` at `b3420e4`; development now continues on `feat/p01-foundation`.
|
||||||
- The configured SSH fetch endpoint still refuses connections and the LAN SSH endpoint rejects the available key, but the approved HTTP push URL is operational.
|
- The configured SSH fetch endpoint still refuses connections and the LAN SSH endpoint rejects the available key, but the approved HTTP push URL is operational.
|
||||||
- Forgejo runner labels/jobs remain unverified, so the committed workflow is not claimed successful.
|
- Forgejo runner labels/jobs remain unverified, so the committed workflow is not claimed successful.
|
||||||
- Real UNC execution still requires a user-authorized disposable fixture.
|
- Real UNC execution still requires a user-authorized disposable fixture.
|
||||||
|
|
||||||
|
## P01 Foundation (active)
|
||||||
|
|
||||||
|
### Objective
|
||||||
|
|
||||||
|
Turn the P00 Spike skeleton into a durable application foundation without pulling Batch 2 connection-profile behavior forward across an unresolved document boundary.
|
||||||
|
|
||||||
|
### Ordered work
|
||||||
|
|
||||||
|
1. Initialize a persistent SQLite database in the Tauri application-data directory.
|
||||||
|
2. Apply versioned, transactional, idempotent migrations and refuse unknown future schema versions.
|
||||||
|
3. Validate Rust-to-TypeScript bootstrap payloads at runtime.
|
||||||
|
4. Ensure tracing output passes through the shared redaction rules before it reaches a writer.
|
||||||
|
5. Re-verify tray, single-instance, explicit exit, frontend, Rust, E2E, development startup, and production build behavior.
|
||||||
|
6. Record the Profile CRUD stage conflict before changing its schema or IPC.
|
||||||
|
|
||||||
|
### Paused boundary
|
||||||
|
|
||||||
|
- `docs/01_Architecture_Design.md` places Profile CRUD in stage 1.
|
||||||
|
- `docs/02_Codex_Implementation_Tasks.md` places ConnectionProfile CRUD in Batch 2.
|
||||||
|
- Because this changes database structure and public IPC, Profile CRUD remains paused under PD-0008 until the stage boundary is explicitly resolved.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## Current phase
|
## Current phase
|
||||||
|
|
||||||
P00 bootstrap implementation and high-risk Spike verification is complete; the feature branch is published and awaiting user PR review.
|
P01 foundation is active on `feat/p01-foundation`; unambiguous foundation work is implemented, while Profile CRUD is paused on a documented stage-boundary conflict.
|
||||||
|
|
||||||
## Completed
|
## Completed
|
||||||
|
|
||||||
|
|
@ -21,15 +21,23 @@ P00 bootstrap implementation and high-risk Spike verification is complete; the f
|
||||||
- Added frontend, Playwright, Rust, integration, Windows-provider, soak, and Forgejo CI entry points.
|
- Added frontend, Playwright, Rust, integration, Windows-provider, soak, and Forgejo CI entry points.
|
||||||
- Built the Windows release executable and SHA-256-recorded NSIS installer.
|
- Built the Windows release executable and SHA-256-recorded NSIS installer.
|
||||||
- Added dependency, Spike, progress, changelog, and pending-decision records.
|
- Added dependency, Spike, progress, changelog, and pending-decision records.
|
||||||
|
- Verified Forgejo PR #1 merged into `main` as `b3420e4`.
|
||||||
|
- Fast-forwarded local `main` and created `feat/p01-foundation` from the merged baseline.
|
||||||
|
- Added persistent SQLite startup initialization with WAL, busy timeout, transactional `user_version` migration, idempotent reopen, and future-version rejection.
|
||||||
|
- Added strict Zod validation for the Rust bootstrap IPC payload and exposed the active database schema version.
|
||||||
|
- Added a redacting tracing writer that sanitizes structured fields and rendered message content before output.
|
||||||
|
- Verified a real Tauri development start created the application database in the Windows app-data directory.
|
||||||
|
- Built the P01 Windows release executable and NSIS installer.
|
||||||
- Committed the implementation, test, and CI increments with Conventional Commit subjects.
|
- Committed the implementation, test, and CI increments with Conventional Commit subjects.
|
||||||
|
|
||||||
## In progress
|
## In progress
|
||||||
|
|
||||||
- Preparing the final PR draft and handoff report without merging `main`.
|
- Recording the Profile CRUD stage conflict and preparing the verified P01 foundation increment for remote review.
|
||||||
|
|
||||||
## Remaining
|
## Remaining
|
||||||
|
|
||||||
- Open and review the Forgejo PR from `feat/p00-bootstrap` to `main`; do not merge automatically.
|
- Resolve whether Profile CRUD belongs in P01 (architecture document) or P02/Batch 2 (implementation task document) before changing its database schema or public IPC.
|
||||||
|
- After resolution, complete the selected stage scope and open a PR without automatically merging `main`.
|
||||||
- Run the Forgejo workflow when a compatible runner is available.
|
- Run the Forgejo workflow when a compatible runner is available.
|
||||||
- Execute a real UNC transaction only after an authorized disposable fixture is supplied.
|
- Execute a real UNC transaction only after an authorized disposable fixture is supplied.
|
||||||
- Add the combined end-to-end test that keeps configured streams active while the real Tauri window is hidden to tray.
|
- Add the combined end-to-end test that keeps configured streams active while the real Tauri window is hidden to tray.
|
||||||
|
|
@ -39,24 +47,26 @@ P00 bootstrap implementation and high-risk Spike verification is complete; the f
|
||||||
- Configured Forgejo SSH `localhost:18086` refuses connections.
|
- Configured Forgejo SSH `localhost:18086` refuses connections.
|
||||||
- LAN SSH `192.168.31.210:18086` responds but rejects the available public key.
|
- LAN SSH `192.168.31.210:18086` responds but rejects the available public key.
|
||||||
- HTTP Git push is operational after Git Credential Manager reauthentication and is no longer a blocker.
|
- HTTP Git push is operational after Git Credential Manager reauthentication and is no longer a blocker.
|
||||||
|
- Profile CRUD stage ownership conflicts between the architecture and implementation task documents; implementation is paused because it affects database structure and public IPC.
|
||||||
- Forgejo runner labels/jobs could not be verified; the jobs API endpoint returned 404.
|
- Forgejo runner labels/jobs could not be verified; the jobs API endpoint returned 404.
|
||||||
|
|
||||||
## Test status
|
## Test status
|
||||||
|
|
||||||
- `pnpm check:frontend`: passed; 1 Vitest test and production Vite build.
|
- `npm run check:frontend`: passed; 2 Vitest tests and production Vite build.
|
||||||
- `pnpm test:e2e`: passed; 1 Chromium smoke test.
|
- `pnpm test:e2e`: passed; 1 Chromium smoke test.
|
||||||
- Rust fmt/check/Clippy with warnings denied: passed.
|
- Rust fmt/check/Clippy with warnings denied: passed.
|
||||||
- `cargo test --workspace`: 40 passed, 2 explicit manual tests ignored.
|
- `cargo test --workspace`: 44 passed, 2 explicit manual tests ignored.
|
||||||
- Controlled Windows UIA/PrintWindow smoke: 1 passed.
|
- Controlled Windows UIA/PrintWindow smoke: 1 passed.
|
||||||
- Corrected dual-SSE soak: 1800.02 seconds, 1800 companion events, 1801 operations events, passed.
|
- Corrected dual-SSE soak: 1800.02 seconds, 1800 companion events, 1801 operations events, passed.
|
||||||
- Protocol Schema drift check: passed.
|
- Protocol Schema drift check: passed.
|
||||||
- Tauri development smoke, release executable, and NSIS installer build: passed.
|
- P01 Tauri development startup and application-data SQLite creation: passed.
|
||||||
|
- P01 release executable and NSIS installer: passed after repairing the missing official `libsqlite3-sys` binding cache; installer SHA-256 `B8858CBE2F4673FAF40799C1243BCAB0748D194FA3AD67FBD33DDCF26CF27189`.
|
||||||
- pnpm 11.9.0 frozen lockfile-only validation: passed using a local temporary store to avoid the pnpm UNC project-registry limitation.
|
- pnpm 11.9.0 frozen lockfile-only validation: passed using a local temporary store to avoid the pnpm UNC project-registry limitation.
|
||||||
- Forgejo CI and a real UNC transaction were not executed and are not claimed successful.
|
- Forgejo CI and a real UNC transaction were not executed and are not claimed successful.
|
||||||
|
|
||||||
## Current branch
|
## Current branch
|
||||||
|
|
||||||
`feat/p00-bootstrap`
|
`feat/p01-foundation`
|
||||||
|
|
||||||
## Recent commits
|
## Recent commits
|
||||||
|
|
||||||
|
|
@ -65,8 +75,11 @@ P00 bootstrap implementation and high-risk Spike verification is complete; the f
|
||||||
- `01607c6 feat(p00): add Tauri desktop spike foundation`
|
- `01607c6 feat(p00): add Tauri desktop spike foundation`
|
||||||
- `69b432b test(p00): add frontend browser rust and windows checks`
|
- `69b432b test(p00): add frontend browser rust and windows checks`
|
||||||
- `d4af979 ci(forgejo): add portable and windows quality workflows`
|
- `d4af979 ci(forgejo): add portable and windows quality workflows`
|
||||||
|
- `72a16cb docs(p00): record Forgejo branch publication`
|
||||||
|
- `b3420e4 Merge pull request 'feat(p00): bootstrap Tauri desktop and validate high-risk spikes' (#1)`
|
||||||
|
- `ed74342 feat(foundation): add persistent bootstrap safeguards`
|
||||||
- `353a439 docs(p00): record spike results and unresolved boundaries`
|
- `353a439 docs(p00): record spike results and unresolved boundaries`
|
||||||
|
|
||||||
## Next step
|
## Next step
|
||||||
|
|
||||||
Provide the verified test report and PR draft. The user can then review the Forgejo diff and decide whether to merge; `main` remains unchanged by this workflow.
|
Obtain an explicit decision for PD-0008 before implementing Profile CRUD. Continue other P01 work only if it does not change the disputed profile database or public IPC boundary.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
# P01 Foundation Progress Report
|
||||||
|
|
||||||
|
Date: 2026-07-18
|
||||||
|
|
||||||
|
## Status
|
||||||
|
|
||||||
|
P01 foundation work is partially complete on `feat/p01-foundation`. The unambiguous Batch 1 foundation items are implemented and verified. Profile CRUD is intentionally paused under PD-0008 because the architecture and implementation task documents assign it to different stages.
|
||||||
|
|
||||||
|
## Completed
|
||||||
|
|
||||||
|
- Verified P00 PR #1 merged into `main` at `b3420e4`.
|
||||||
|
- Fast-forwarded local `main` and created `feat/p01-foundation`.
|
||||||
|
- Added a persistent SQLite database under the Tauri application-data directory.
|
||||||
|
- Added WAL mode, a bounded busy timeout, foreign-key enforcement, and transactional `user_version` migration.
|
||||||
|
- Added idempotent reopen/persistence tests and rejection of databases newer than the supported schema.
|
||||||
|
- Added the database schema version to the bootstrap IPC response.
|
||||||
|
- Added strict frontend Zod validation for the IPC payload and a malformed-payload test.
|
||||||
|
- Added a tracing writer that redacts output before writing.
|
||||||
|
- Retained the existing tray menu, close-to-tray, explicit quit, and single-instance focus behavior.
|
||||||
|
|
||||||
|
## Verification
|
||||||
|
|
||||||
|
| Check | Result |
|
||||||
|
| ------------------------------------------------------- | ------------------------------------------------------------------ |
|
||||||
|
| Frontend format, ESLint, TypeScript, Vitest, Vite build | Passed; 2 Vitest tests |
|
||||||
|
| Playwright Chromium | Passed; 1 test |
|
||||||
|
| Rust fmt, Clippy with warnings denied, check | Passed |
|
||||||
|
| Rust tests | Passed; 44 normal tests, 2 explicit manual tests ignored |
|
||||||
|
| Persistent SQLite reopen and migration tests | Passed |
|
||||||
|
| Logging redaction writer test | Passed |
|
||||||
|
| Tauri development startup | Passed |
|
||||||
|
| Windows application-data SQLite creation | Passed; database created at startup |
|
||||||
|
| Tauri release executable | Passed |
|
||||||
|
| NSIS installer | Passed; 3,793,884 bytes |
|
||||||
|
| NSIS SHA-256 | `B8858CBE2F4673FAF40799C1243BCAB0748D194FA3AD67FBD33DDCF26CF27189` |
|
||||||
|
|
||||||
|
## Build environment note
|
||||||
|
|
||||||
|
The first release attempts failed because the `libsqlite3-sys` release output directory did not contain `bindgen.rs`, although the crate build script had produced the SQLite static library. Cleaning only that package did not restore the file.
|
||||||
|
|
||||||
|
The official pre-generated `bindgen_bundled_version.rs` from the installed `libsqlite3-sys 0.38.1` crate source was copied to the exact `OUT_DIR/bindgen.rs` location expected by the crate's own `build.rs`. Source and destination SHA-256 values matched:
|
||||||
|
|
||||||
|
`5B5A37A74DC728FB0BCD041867EB577C03C95E2FE46285262C589A3B1CD4BBAC`
|
||||||
|
|
||||||
|
The production build and NSIS bundle then completed. This is recorded as an environment cache repair, not a repository or dependency change.
|
||||||
|
|
||||||
|
## Paused boundary
|
||||||
|
|
||||||
|
Profile CRUD is not implemented in this increment.
|
||||||
|
|
||||||
|
- Architecture stage 1 includes Profile CRUD.
|
||||||
|
- Implementation Batch 2 includes ConnectionProfile CRUD.
|
||||||
|
- The conflict affects database structure and public IPC.
|
||||||
|
- PD-0008 requires an explicit stage-boundary decision before work resumes.
|
||||||
|
|
||||||
|
## Not claimed
|
||||||
|
|
||||||
|
- P01 is not declared complete while PD-0008 is unresolved.
|
||||||
|
- Forgejo CI has not run.
|
||||||
|
- No Profile CRUD, profile UI, or slot assignment was added.
|
||||||
|
- No real credential or destructive file operation was used.
|
||||||
|
|
@ -1,33 +1,55 @@
|
||||||
|
use std::{path::Path, sync::Mutex, time::Duration};
|
||||||
|
|
||||||
use rusqlite::{Connection, OptionalExtension, params};
|
use rusqlite::{Connection, OptionalExtension, params};
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
|
pub const CURRENT_SCHEMA_VERSION: u32 = 1;
|
||||||
|
|
||||||
|
pub struct ApplicationDatabase {
|
||||||
|
store: Mutex<ProfileMessageStore>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApplicationDatabase {
|
||||||
|
pub fn open(path: impl AsRef<Path>) -> Result<Self, DatabaseError> {
|
||||||
|
Ok(Self {
|
||||||
|
store: Mutex::new(ProfileMessageStore::open(path)?),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn schema_version(&self) -> Result<u32, DatabaseError> {
|
||||||
|
self.store
|
||||||
|
.lock()
|
||||||
|
.map_err(|_| DatabaseError::LockPoisoned)?
|
||||||
|
.schema_version()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct ProfileMessageStore {
|
pub struct ProfileMessageStore {
|
||||||
connection: Connection,
|
connection: Connection,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ProfileMessageStore {
|
impl ProfileMessageStore {
|
||||||
pub fn in_memory() -> Result<Self, DatabaseError> {
|
pub fn open(path: impl AsRef<Path>) -> Result<Self, DatabaseError> {
|
||||||
let connection = Connection::open_in_memory()?;
|
Self::from_connection(Connection::open(path)?, true)
|
||||||
let store = Self { connection };
|
|
||||||
store.migrate()?;
|
|
||||||
Ok(store)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn migrate(&self) -> Result<(), DatabaseError> {
|
pub fn in_memory() -> Result<Self, DatabaseError> {
|
||||||
self.connection.execute_batch(
|
Self::from_connection(Connection::open_in_memory()?, false)
|
||||||
"
|
}
|
||||||
PRAGMA foreign_keys = ON;
|
|
||||||
CREATE TABLE IF NOT EXISTS messages (
|
fn from_connection(
|
||||||
profile_id TEXT NOT NULL,
|
mut connection: Connection,
|
||||||
server_instance_id TEXT NOT NULL,
|
persistent: bool,
|
||||||
conversation_id TEXT NOT NULL,
|
) -> Result<Self, DatabaseError> {
|
||||||
message_id TEXT NOT NULL,
|
configure_connection(&connection, persistent)?;
|
||||||
content TEXT NOT NULL,
|
migrate(&mut connection)?;
|
||||||
PRIMARY KEY (profile_id, server_instance_id, conversation_id, message_id)
|
Ok(Self { connection })
|
||||||
);
|
}
|
||||||
",
|
|
||||||
)?;
|
pub fn schema_version(&self) -> Result<u32, DatabaseError> {
|
||||||
Ok(())
|
Ok(self
|
||||||
|
.connection
|
||||||
|
.pragma_query_value(None, "user_version", |row| row.get(0))?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn insert_message(
|
pub fn insert_message(
|
||||||
|
|
@ -84,16 +106,128 @@ impl ProfileMessageStore {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn configure_connection(connection: &Connection, persistent: bool) -> Result<(), DatabaseError> {
|
||||||
|
connection.pragma_update(None, "foreign_keys", "ON")?;
|
||||||
|
connection.busy_timeout(Duration::from_secs(5))?;
|
||||||
|
if persistent {
|
||||||
|
connection.pragma_update(None, "journal_mode", "WAL")?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn migrate(connection: &mut Connection) -> Result<(), DatabaseError> {
|
||||||
|
let found: u32 = connection.pragma_query_value(None, "user_version", |row| row.get(0))?;
|
||||||
|
|
||||||
|
if found > CURRENT_SCHEMA_VERSION {
|
||||||
|
return Err(DatabaseError::UnsupportedSchemaVersion {
|
||||||
|
found,
|
||||||
|
supported: CURRENT_SCHEMA_VERSION,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if found == 0 {
|
||||||
|
let transaction = connection.transaction()?;
|
||||||
|
transaction.execute_batch(
|
||||||
|
"
|
||||||
|
CREATE TABLE messages (
|
||||||
|
profile_id TEXT NOT NULL,
|
||||||
|
server_instance_id TEXT NOT NULL,
|
||||||
|
conversation_id TEXT NOT NULL,
|
||||||
|
message_id TEXT NOT NULL,
|
||||||
|
content TEXT NOT NULL,
|
||||||
|
PRIMARY KEY (profile_id, server_instance_id, conversation_id, message_id)
|
||||||
|
);
|
||||||
|
PRAGMA user_version = 1;
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
transaction.commit()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum DatabaseError {
|
pub enum DatabaseError {
|
||||||
#[error("SQLite operation failed")]
|
#[error("SQLite operation failed")]
|
||||||
Sqlite(#[from] rusqlite::Error),
|
Sqlite(#[from] rusqlite::Error),
|
||||||
|
#[error("database schema version {found} is newer than supported version {supported}")]
|
||||||
|
UnsupportedSchemaVersion { found: u32, supported: u32 },
|
||||||
|
#[error("database state lock is unavailable")]
|
||||||
|
LockPoisoned,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn creates_and_reopens_a_persistent_migrated_database() {
|
||||||
|
let directory = tempfile::tempdir().expect("temporary directory");
|
||||||
|
let path = directory.path().join("desktop.sqlite3");
|
||||||
|
|
||||||
|
{
|
||||||
|
let store = ProfileMessageStore::open(&path).expect("open database");
|
||||||
|
assert_eq!(
|
||||||
|
store.schema_version().expect("schema version"),
|
||||||
|
CURRENT_SCHEMA_VERSION
|
||||||
|
);
|
||||||
|
store
|
||||||
|
.insert_message(
|
||||||
|
"profile-a",
|
||||||
|
"server-a",
|
||||||
|
"conversation-a",
|
||||||
|
"message-a",
|
||||||
|
"persisted",
|
||||||
|
)
|
||||||
|
.expect("insert message");
|
||||||
|
}
|
||||||
|
|
||||||
|
let reopened = ProfileMessageStore::open(&path).expect("reopen database");
|
||||||
|
assert_eq!(
|
||||||
|
reopened.schema_version().expect("schema version"),
|
||||||
|
CURRENT_SCHEMA_VERSION
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
reopened
|
||||||
|
.message_content("profile-a", "server-a", "conversation-a", "message-a")
|
||||||
|
.expect("query message")
|
||||||
|
.as_deref(),
|
||||||
|
Some("persisted")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn refuses_a_database_from_a_newer_schema_version() {
|
||||||
|
let directory = tempfile::tempdir().expect("temporary directory");
|
||||||
|
let path = directory.path().join("future.sqlite3");
|
||||||
|
let connection = Connection::open(&path).expect("create database");
|
||||||
|
connection
|
||||||
|
.pragma_update(None, "user_version", CURRENT_SCHEMA_VERSION + 1)
|
||||||
|
.expect("set future version");
|
||||||
|
drop(connection);
|
||||||
|
|
||||||
|
assert!(matches!(
|
||||||
|
ProfileMessageStore::open(path),
|
||||||
|
Err(DatabaseError::UnsupportedSchemaVersion {
|
||||||
|
found: 2,
|
||||||
|
supported: CURRENT_SCHEMA_VERSION
|
||||||
|
})
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn repeated_migration_is_idempotent() {
|
||||||
|
let store = ProfileMessageStore::in_memory().expect("store");
|
||||||
|
assert_eq!(
|
||||||
|
store.schema_version().expect("schema version"),
|
||||||
|
CURRENT_SCHEMA_VERSION
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
store.schema_version().expect("schema version"),
|
||||||
|
CURRENT_SCHEMA_VERSION
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn identical_remote_ids_remain_isolated_by_profile_and_server() {
|
fn identical_remote_ids_remain_isolated_by_profile_and_server() {
|
||||||
let store = ProfileMessageStore::in_memory().expect("store");
|
let store = ProfileMessageStore::in_memory().expect("store");
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,14 @@
|
||||||
pub mod database;
|
pub mod database;
|
||||||
pub mod diagnostics;
|
pub mod diagnostics;
|
||||||
pub mod file_transfer;
|
pub mod file_transfer;
|
||||||
|
pub mod logging;
|
||||||
pub mod networking;
|
pub mod networking;
|
||||||
pub mod secure_store;
|
pub mod secure_store;
|
||||||
pub mod windows;
|
pub mod windows;
|
||||||
|
|
||||||
|
use database::ApplicationDatabase;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
use tauri::{
|
use tauri::{
|
||||||
Manager, WindowEvent,
|
Manager, WindowEvent,
|
||||||
menu::{Menu, MenuItem},
|
menu::{Menu, MenuItem},
|
||||||
|
|
@ -16,30 +19,31 @@ use tauri::{
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
struct BootstrapStatus {
|
struct BootstrapStatus {
|
||||||
app_version: &'static str,
|
app_version: &'static str,
|
||||||
|
database_schema_version: u32,
|
||||||
platform: &'static str,
|
platform: &'static str,
|
||||||
rust_core: &'static str,
|
rust_core: &'static str,
|
||||||
protocol_version: &'static str,
|
protocol_version: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn bootstrap_status() -> BootstrapStatus {
|
fn bootstrap_status(
|
||||||
BootstrapStatus {
|
database: tauri::State<'_, ApplicationDatabase>,
|
||||||
|
) -> Result<BootstrapStatus, String> {
|
||||||
|
let database_schema_version = database
|
||||||
|
.schema_version()
|
||||||
|
.map_err(|_| "database status is unavailable".to_owned())?;
|
||||||
|
|
||||||
|
Ok(BootstrapStatus {
|
||||||
app_version: env!("CARGO_PKG_VERSION"),
|
app_version: env!("CARGO_PKG_VERSION"),
|
||||||
platform: "windows",
|
platform: "windows",
|
||||||
rust_core: "ready",
|
rust_core: "ready",
|
||||||
protocol_version: desktop_protocol::PROTOCOL_VERSION,
|
protocol_version: desktop_protocol::PROTOCOL_VERSION,
|
||||||
}
|
database_schema_version,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run() {
|
pub fn run() {
|
||||||
tracing_subscriber::fmt()
|
logging::init();
|
||||||
.with_env_filter(
|
|
||||||
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
||||||
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
|
||||||
)
|
|
||||||
.with_target(false)
|
|
||||||
.compact()
|
|
||||||
.init();
|
|
||||||
|
|
||||||
tauri::Builder::default()
|
tauri::Builder::default()
|
||||||
.plugin(tauri_plugin_single_instance::init(|app, _, _| {
|
.plugin(tauri_plugin_single_instance::init(|app, _, _| {
|
||||||
|
|
@ -49,6 +53,12 @@ pub fn run() {
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.setup(|app| {
|
.setup(|app| {
|
||||||
|
let app_data_dir = app.path().app_data_dir()?;
|
||||||
|
std::fs::create_dir_all(&app_data_dir)?;
|
||||||
|
app.manage(ApplicationDatabase::open(
|
||||||
|
app_data_dir.join("astrbot-desktop.sqlite3"),
|
||||||
|
)?);
|
||||||
|
|
||||||
let show = MenuItem::with_id(app, "show", "Show AstrBot Desktop", true, None::<&str>)?;
|
let show = MenuItem::with_id(app, "show", "Show AstrBot Desktop", true, None::<&str>)?;
|
||||||
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
let quit = MenuItem::with_id(app, "quit", "Quit", true, None::<&str>)?;
|
||||||
let menu = Menu::with_items(app, &[&show, &quit])?;
|
let menu = Menu::with_items(app, &[&show, &quit])?;
|
||||||
|
|
|
||||||
170
src-tauri/src/logging.rs
普通文件
170
src-tauri/src/logging.rs
普通文件
|
|
@ -0,0 +1,170 @@
|
||||||
|
use std::io::{self, Write};
|
||||||
|
|
||||||
|
use tracing_subscriber::fmt::MakeWriter;
|
||||||
|
|
||||||
|
use crate::diagnostics::redaction::Redactor;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct RedactingMakeWriter<M> {
|
||||||
|
inner: M,
|
||||||
|
redactor: Redactor,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<M> RedactingMakeWriter<M> {
|
||||||
|
pub fn new(inner: M) -> Self {
|
||||||
|
Self {
|
||||||
|
inner,
|
||||||
|
redactor: Redactor::default(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
fn with_redactor(inner: M, redactor: Redactor) -> Self {
|
||||||
|
Self { inner, redactor }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'writer, M> MakeWriter<'writer> for RedactingMakeWriter<M>
|
||||||
|
where
|
||||||
|
M: MakeWriter<'writer>,
|
||||||
|
M::Writer: Write,
|
||||||
|
{
|
||||||
|
type Writer = RedactingWriter<M::Writer>;
|
||||||
|
|
||||||
|
fn make_writer(&'writer self) -> Self::Writer {
|
||||||
|
RedactingWriter {
|
||||||
|
inner: self.inner.make_writer(),
|
||||||
|
redactor: self.redactor.clone(),
|
||||||
|
buffer: Vec::new(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct RedactingWriter<W: Write> {
|
||||||
|
inner: W,
|
||||||
|
redactor: Redactor,
|
||||||
|
buffer: Vec<u8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<W: Write> RedactingWriter<W> {
|
||||||
|
fn flush_redacted(&mut self) -> io::Result<()> {
|
||||||
|
if self.buffer.is_empty() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let rendered = String::from_utf8_lossy(&self.buffer);
|
||||||
|
let redacted = self.redactor.redact(&rendered);
|
||||||
|
self.inner.write_all(redacted.as_bytes())?;
|
||||||
|
self.buffer.clear();
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<W: Write> Write for RedactingWriter<W> {
|
||||||
|
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
|
||||||
|
self.buffer.extend_from_slice(buffer);
|
||||||
|
Ok(buffer.len())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> io::Result<()> {
|
||||||
|
self.flush_redacted()?;
|
||||||
|
self.inner.flush()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<W: Write> Drop for RedactingWriter<W> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
let _ = self.flush_redacted();
|
||||||
|
let _ = self.inner.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init() {
|
||||||
|
tracing_subscriber::fmt()
|
||||||
|
.with_env_filter(
|
||||||
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
||||||
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
||||||
|
)
|
||||||
|
.with_target(false)
|
||||||
|
.compact()
|
||||||
|
.with_writer(RedactingMakeWriter::new(std::io::stderr))
|
||||||
|
.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Default)]
|
||||||
|
struct SharedMakeWriter {
|
||||||
|
output: Arc<Mutex<Vec<u8>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl SharedMakeWriter {
|
||||||
|
fn contents(&self) -> String {
|
||||||
|
String::from_utf8(self.output.lock().expect("output lock").clone())
|
||||||
|
.expect("UTF-8 output")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct SharedWriter {
|
||||||
|
output: Arc<Mutex<Vec<u8>>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Write for SharedWriter {
|
||||||
|
fn write(&mut self, buffer: &[u8]) -> io::Result<usize> {
|
||||||
|
self.output
|
||||||
|
.lock()
|
||||||
|
.expect("output lock")
|
||||||
|
.extend_from_slice(buffer);
|
||||||
|
Ok(buffer.len())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn flush(&mut self) -> io::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'writer> MakeWriter<'writer> for SharedMakeWriter {
|
||||||
|
type Writer = SharedWriter;
|
||||||
|
|
||||||
|
fn make_writer(&'writer self) -> Self::Writer {
|
||||||
|
SharedWriter {
|
||||||
|
output: self.output.clone(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn redacts_structured_fields_and_message_content_before_writing() {
|
||||||
|
let sink = SharedMakeWriter::default();
|
||||||
|
let known_secret = format!("canary-{}", uuid::Uuid::new_v4());
|
||||||
|
let subscriber = tracing_subscriber::fmt()
|
||||||
|
.without_time()
|
||||||
|
.with_ansi(false)
|
||||||
|
.with_target(false)
|
||||||
|
.with_writer(RedactingMakeWriter::with_redactor(
|
||||||
|
sink.clone(),
|
||||||
|
Redactor::new([&known_secret]),
|
||||||
|
))
|
||||||
|
.finish();
|
||||||
|
|
||||||
|
tracing::subscriber::with_default(subscriber, || {
|
||||||
|
tracing::info!(
|
||||||
|
password = "test-password",
|
||||||
|
authorization = "Bearer abcdefghijklmnop",
|
||||||
|
endpoint = "https://alice:password@example.test/path",
|
||||||
|
"known={known_secret}"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
let output = sink.contents();
|
||||||
|
assert!(!output.contains("test-password"));
|
||||||
|
assert!(!output.contains("abcdefghijklmnop"));
|
||||||
|
assert!(!output.contains("alice:password"));
|
||||||
|
assert!(!output.contains(&known_secret));
|
||||||
|
assert!(output.contains(crate::diagnostics::redaction::REDACTED));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ describe("App", () => {
|
||||||
platform: "windows",
|
platform: "windows",
|
||||||
rustCore: "ready",
|
rustCore: "ready",
|
||||||
protocolVersion: "desktop-v1alpha1",
|
protocolVersion: "desktop-v1alpha1",
|
||||||
|
databaseSchemaVersion: 1,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -24,4 +25,19 @@ describe("App", () => {
|
||||||
expect(await screen.findByText("ready")).toBeInTheDocument();
|
expect(await screen.findByText("ready")).toBeInTheDocument();
|
||||||
expect(screen.getByText("desktop-v1alpha1")).toBeInTheDocument();
|
expect(screen.getByText("desktop-v1alpha1")).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("rejects an invalid Rust IPC payload", async () => {
|
||||||
|
vi.mocked(invoke).mockResolvedValueOnce({
|
||||||
|
appVersion: "0.1.0-alpha.0",
|
||||||
|
platform: "windows",
|
||||||
|
rustCore: "unexpected",
|
||||||
|
protocolVersion: "desktop-v1alpha1",
|
||||||
|
databaseSchemaVersion: 1,
|
||||||
|
});
|
||||||
|
|
||||||
|
render(<App />);
|
||||||
|
|
||||||
|
expect(await screen.findByText(/IPC unavailable:/)).toBeInTheDocument();
|
||||||
|
expect(screen.queryByText("unexpected")).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
11
src/App.tsx
11
src/App.tsx
|
|
@ -1,13 +1,14 @@
|
||||||
import { invoke } from "@tauri-apps/api/core";
|
import { invoke } from "@tauri-apps/api/core";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
|
|
||||||
import type { BootstrapStatus } from "./types/bootstrap";
|
import { bootstrapStatusSchema, type BootstrapStatus } from "./types/bootstrap";
|
||||||
|
|
||||||
const initialStatus: BootstrapStatus = {
|
const initialStatus: BootstrapStatus = {
|
||||||
appVersion: "unknown",
|
appVersion: "unknown",
|
||||||
platform: "unknown",
|
platform: "unknown",
|
||||||
rustCore: "pending",
|
rustCore: "pending",
|
||||||
protocolVersion: "desktop-v1alpha1",
|
protocolVersion: "desktop-v1alpha1",
|
||||||
|
databaseSchemaVersion: 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
export function App() {
|
export function App() {
|
||||||
|
|
@ -16,8 +17,8 @@ export function App() {
|
||||||
|
|
||||||
const refreshStatus = useCallback(async () => {
|
const refreshStatus = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const result = await invoke<BootstrapStatus>("bootstrap_status");
|
const result = await invoke<unknown>("bootstrap_status");
|
||||||
setStatus(result);
|
setStatus(bootstrapStatusSchema.parse(result));
|
||||||
setError(null);
|
setError(null);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
setError(reason instanceof Error ? reason.message : String(reason));
|
setError(reason instanceof Error ? reason.message : String(reason));
|
||||||
|
|
@ -44,6 +45,10 @@ export function App() {
|
||||||
<StatusCard label="App Version" value={status.appVersion} />
|
<StatusCard label="App Version" value={status.appVersion} />
|
||||||
<StatusCard label="Protocol" value={status.protocolVersion} />
|
<StatusCard label="Protocol" value={status.protocolVersion} />
|
||||||
</section>
|
</section>
|
||||||
|
<StatusCard
|
||||||
|
label="Database Schema"
|
||||||
|
value={String(status.databaseSchemaVersion)}
|
||||||
|
/>
|
||||||
|
|
||||||
{error ? <p className="error-banner">IPC unavailable: {error}</p> : null}
|
{error ? <p className="error-banner">IPC unavailable: {error}</p> : null}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
export interface BootstrapStatus {
|
import { z } from "zod";
|
||||||
appVersion: string;
|
|
||||||
platform: string;
|
export const bootstrapStatusSchema = z
|
||||||
rustCore: "ready" | "pending";
|
.object({
|
||||||
protocolVersion: string;
|
appVersion: z.string().min(1),
|
||||||
}
|
platform: z.string().min(1),
|
||||||
|
rustCore: z.enum(["ready", "pending"]),
|
||||||
|
protocolVersion: z.string().min(1),
|
||||||
|
databaseSchemaVersion: z.number().int().positive(),
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
|
export type BootstrapStatus = z.infer<typeof bootstrapStatusSchema>;
|
||||||
|
|
|
||||||
正在加载…
添加表格
在新工单中引用