Skip to content

Commit d5f2840

Browse files
lseongjooclaude
andcommitted
Test a failed draft database setup; say what quitting forgets and what stays (#31)
- AgentCatalogTests: a file that exists but is not SQLite (the handle is opened, setup SQL fails) and a path under a regular file both return nil from SQLiteDraftStore, 50 times each, with no crash and the file left byte-identical. Stated in the test: this does not prove the handle is closed once; SQLite rejects a second close quietly here, and the run also passes with `db = nil` removed. - docs P-06: quitting drops helper connections, receipt proofs, this-run approvals of unidentified hosts, the instruction share selection and the closed-draft key memory; drafts stay in drafts.sqlite and registered apps' approvals, revocations and receipt choices in agent-approvals.json. The old line said open drafts and approval records were lost on quit. Agent: Claude Code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent b42d5ad commit d5f2840

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

‎Tests/AgentCatalogTests.swift‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ enum CodeExplanation { static let noChange = "변경 없음" }
267267
precondition(titled.title == "제목만 다른 글" && plain.title == nil && blank.title == nil)
268268
precondition(titled.fingerprintHex != plain.fingerprintHex && blank.fingerprintHex == plain.fingerprintHex)
269269

270+
// A setup that fails after SQLite handed out a handle (a file that exists but is
271+
// not a database) returns nil without crashing and leaves the file as it was; a
272+
// parent that is a regular file fails before any handle. This does not prove the
273+
// handle is closed only once: SQLite rejects a second close of a freed handle
274+
// quietly here (SQLITE_MISUSE), so the same run passes without `db = nil`.
275+
let notDatabase = directory.appendingPathComponent("not-a-database.sqlite")
276+
let junk = Data(repeating: 0x5A, count: 4096)
277+
try! junk.write(to: notDatabase)
278+
let fileParent = directory.appendingPathComponent("plain-file")
279+
try! Data("x".utf8).write(to: fileParent)
280+
for _ in 0..<50 {
281+
precondition(SQLiteDraftStore(url: notDatabase) == nil)
282+
precondition(SQLiteDraftStore(url: fileParent.appendingPathComponent("drafts.sqlite")) == nil)
283+
}
284+
precondition(try! Data(contentsOf: notDatabase) == junk)
285+
270286
let url = directory.appendingPathComponent("drafts.sqlite")
271287
func open() -> ExplanationDraftWorkspace { ExplanationDraftWorkspace(store: SQLiteDraftStore(url: url)!) }
272288
var work = open()
@@ -367,7 +383,7 @@ enum CodeExplanation { static let noChange = "변경 없음" }
367383
let reopened = ExplanationDraftWorkspace(store: manualStore)
368384
precondition(reopened.display == "직접 쓴 글" && reopened.editorDocumentID == manualDocID)
369385
precondition(reopened.newDocument() && manualStore.activeID == nil)
370-
print("Draft history: title rules, title kept out of body and playback, key duplicate/conflict, fallback title, 154 documents, search-time arrival, restart restore, storage failure, failed park keeps editor, manual draft reopens passed")
386+
print("Draft history: title rules, title kept out of body and playback, key duplicate/conflict, fallback title, 154 documents, search-time arrival, restart restore, storage failure, failed database setup, failed park keeps editor, manual draft reopens passed")
371387
}
372388

373389
/// Approval record rules, with real P-256 signatures and a controllable clock.

‎docs/mcp-explanation-drafts.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ command = "/absolute/path/to/Codebasic TTS.app/Contents/Helpers/CodebasicAgentMC
2828
- 호환용 기존 기본 지시 조회와 `speak_text`는 각각 그대로입니다. 증명 없는 이전 `mcp_tts_draft.py`는 자동 수신하지 않으며 붙여넣기를 안내합니다. 각 권한은 별개입니다.
2929
- `title`은 대본 목록과 편집기 머리에만 보이는 이름입니다. 본문·복사·자막·합성·재생에는 들어가지 않고, **화면 글 그대로 읽기**도 본문만 읽습니다. 한 줄, 120자와 UTF-8 512바이트까지이며 넘으면 줄이지 않고 `too_large`로 거절합니다. 없거나 공백뿐이면 본문에서 공백이 아닌 첫 줄을 목록 이름으로 씁니다.
3030
- 지시·화면 글·음성 대본은 각각 UTF-8 8 KiB(8192바이트)이고, 한 요청 프레임은 100 KiB입니다. 한도를 넘는 글은 자르지 않고 `too_large`로 거절하며 응답에 넘은 필드와 바이트 수를 담습니다. `tts_agent_status`의 `limits`에서 두 한도를 읽을 수 있습니다. 대본 수에는 한도가 없습니다. 받은 대본과 직접 쓴 글은 앱 데이터 폴더의 `drafts.sqlite`(0600)에 저장되어 앱을 다시 실행해도 목록·수정본·받은 원문이 그대로 돌아옵니다. 저장에 실패하면 새 수신만 `busy`로 거절하고 기존 글은 건드리지 않습니다. 앱 시작 때 `drafts.sqlite`를 열 수 없으면 목록은 이번 실행 동안 메모리에서만 동작하고, 종료하면 사라질 대본을 받았다고 답하지 않도록 에이전트 대본은 모두 `busy`로 거절하며 탭에 안내합니다. 모든 거절 응답은 `structuredContent.status`에 사유 코드를 담고, 앱의 연결 영역에도 사유가 표시됩니다. 새 대본은 분당 6개, 시간당 60개까지 받습니다. 두 한도 모두 시간이 지나면 풀리며, 받기를 직접 껐다 켜면 새로 셉니다. 같은 전송 키에 제목·본문·음성 대본이 모두 같으면 `duplicate`, 하나라도 다르면 `conflict`이며 기존 대본은 바뀌지 않습니다. 저장된 대본이 목록에 있는 동안에는 앱을 다시 실행해도 같은 답을 합니다. 목록에서 닫은 대본의 키는 에이전트마다 최근 128개까지, 앱이 실행 중인 동안만 기억합니다. 기존의 한도 초과 원문은 자르지 않으며 공유되지 않습니다.
31-
- 열린 대본, 수신 증명, 도우미 승인 기록은 앱을 종료하면 사라집니다. 재생 후에는 기존 설정에 따라 음성 캐시·기록에 남을 수 있습니다.
31+
- 앱을 종료하면 도우미 연결, 수신 증명, 앱을 식별할 수 없어 이번 실행에만 허용한 승인, 지시 공유 선택, 닫은 대본의 키 기억이 사라집니다. 대본은 `drafts.sqlite`에, 등록된 앱의 승인·철회와 받기 설정은 `agent-approvals.json`에 남습니다(아래 "에이전트 탭 자동 연결" 참고). 재생 후에는 기존 설정에 따라 음성 캐시·기록에 남을 수 있습니다.
3232
- 앱이 비정상 종료되면 앱 재시작 및 다음 승인 시 이 버전이 만든 것으로 확인되고 더 이상 연결되지 않는 소켓에 한해 자동으로 복구합니다. “기존 소켓의 출처를 확인할 수 없어 그대로 두었습니다”가 보이면, 이전 **Codebasic TTS** 앱을 종료하고 새 앱에서 같은 동작을 다시 시도하세요. 계속 막히면 복사·붙여넣기를 사용하세요. 관리자가 정확한 경로가 종료된 이전 앱의 소켓임을 별도로 확인한 경우에만 그 항목을 다른 곳으로 옮길 수 있습니다. 경로 전체나 출처를 모르는 파일은 삭제하지 마세요.
3333

3434
## 연결 유지

0 commit comments

Comments
 (0)