fix(managed): open writable store for experimental candidate insertion
Use a dedicated writable database dependency only for guarded experimental insertion. Ordinary managed history remains read-only; discovery and authorization gates are unchanged. Reproduced SQLite readonly failure in an isolated copy with private startup logs retained and the restored live target untouched. Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
117441c04f
commit
53e59688df
3 files changed
+49
-1
No files matched your search
@@ -31,6 +31,7 @@ type managedIdentity struct {
|
|||||||
type managedDeps struct {
|
type managedDeps struct {
|
||||||
lookup func(string) (string, bool)
|
lookup func(string) (string, bool)
|
||||||
openDB func() (*sql.DB, error)
|
openDB func() (*sql.DB, error)
|
||||||
|
openWriteDB func() (*sql.DB, error)
|
||||||
player playerRunner
|
player playerRunner
|
||||||
run func(string, ...string) error
|
run func(string, ...string) error
|
||||||
script, directory string
|
script, directory string
|
||||||
@@ -42,6 +43,7 @@ func managedDependencies(player playerRunner) managedDeps {
|
|||||||
return managedDeps{
|
return managedDeps{
|
||||||
lookup: os.LookupEnv, player: player,
|
lookup: os.LookupEnv, player: player,
|
||||||
openDB: func() (*sql.DB, error) { return openHistoryStore(databasePath()) },
|
openDB: func() (*sql.DB, error) { return openHistoryStore(databasePath()) },
|
||||||
|
openWriteDB: func() (*sql.DB, error) { return openStore(databasePath()) },
|
||||||
script: "/opt/zapret2/init.d/sysv/zapret2", directory: managedTargetDirectory,
|
script: "/opt/zapret2/init.d/sysv/zapret2", directory: managedTargetDirectory,
|
||||||
verifyRuntime: verifyManagedRuntime, verifySOCKS: verifyManagedSOCKS,
|
verifyRuntime: verifyManagedRuntime, verifySOCKS: verifyManagedSOCKS,
|
||||||
run: func(path string, args ...string) error {
|
run: func(path string, args ...string) error {
|
||||||
|
|||||||
@@ -107,7 +107,10 @@ func managedExperimentalSuffix(m *managedTransaction, d managedDeps) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("fresh GGC identity unavailable")
|
return fmt.Errorf("fresh GGC identity unavailable")
|
||||||
}
|
}
|
||||||
db, err := d.openDB()
|
if d.openWriteDB == nil {
|
||||||
|
return fmt.Errorf("experimental candidate writer unavailable")
|
||||||
|
}
|
||||||
|
db, err := d.openWriteDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestManagedCandidateWriterPreservesReadOnlyHistory(t *testing.T) {
|
||||||
|
t.Setenv("ZAPRET_AUTOTUNE_DB", filepath.Join(t.TempDir(), "candidates.db"))
|
||||||
|
d := managedDependencies(nil)
|
||||||
|
db, err := d.openWriteDB()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
tx, err := db.Begin()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
id, err := insertStrategyCandidate(tx, "googlevideo", []string{"rr1---sn-alpha.googlevideo.com"}, managedGooglevideoArgs, nil)
|
||||||
|
if err != nil {
|
||||||
|
_ = tx.Rollback()
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if err := tx.Commit(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
c, err := readStrategyCandidate(db, id)
|
||||||
|
if err != nil || c.Qualified {
|
||||||
|
t.Fatalf("experimental definition must remain unqualified: %+v %v", c, err)
|
||||||
|
}
|
||||||
|
history, err := d.openDB()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
defer history.Close()
|
||||||
|
if _, err := history.Exec("CREATE TABLE managed_readonly_probe(value INTEGER)"); err == nil {
|
||||||
|
t.Fatal("ordinary managed history became writable")
|
||||||
|
}
|
||||||
|
if _, err := readStrategyCandidate(history, id); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user