privacy: AstrLink Guard is the default local model; its menu stands apart from the switch
Settings > Privacy's "Find with a local model" row put the model menu 2px from the Off/On switch (.prefs .val's gap): two bordered boxes touching. The row's .val now has an 8px gap. With no model picked, pii.Choose is AstrLink Guard. Before, it was Privacy Filter whenever the model was on or Privacy Filter was on disk. Now Privacy Filter is chosen only while the model is on, Privacy Filter is downloaded and AstrLink Guard isn't, so a request isn't held back. In that case masking.picked starts AstrLink Guard's 38 MB download (toGuard, tried again an hour after a failure). Once it is on disk, AstrLink Guard is saved as the pick, unless the user picked a model in between, and Privacy Filter is let go. Existing users: - Privacy Filter on with no pick: moved to AstrLink Guard after the download. Privacy Filter stays on disk and can be picked again. - Privacy Filter explicitly picked: unchanged. - Model off: the menu now shows AstrLink Guard. Run at this tree, on origin/main: - go test ./internal/pii ./internal/masking: ok. TestChoose is updated, with Privacy Filter on disk both off (Guard) and on (PF). - go test ./internal/gui -run 'Budget|I18n': ok. - privacy-model.test.cjs, chromium + webkit, every language, 1100/640: 64/64. The new gap check fails with the CSS line removed (gap 2). - gofmt, vet (darwin, linux nogui, windows), linux and windows builds: ok. Not tried: toGuard's real download and switch-over. It needs the network, and no test covers it.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -3294,6 +3294,7 @@ body:not(.side-nav) #view-settings .set-head.stuck::before { box-shadow: 0 1px 0
|
||||
.set-searching .feat-say { display: none; }
|
||||
.row.pref .sub.feat-why { color: var(--muted); font-size: 11px; }
|
||||
/* the local model's row says a download, a device or an error in full */
|
||||
#privacyModelRow .val { gap: 8px; }
|
||||
#privacyModelRow .sub { white-space: normal; overflow-wrap: anywhere; }
|
||||
/* Privacy › how it's found: the rules, always on while anything is masked,
|
||||
and the local model, which says why it can't be used while nothing is */
|
||||
|
||||
@@ -216,6 +216,12 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
|
||||
assert.equal((await pick.textContent()).trim(), "Privacy Filter");
|
||||
let m = await look(page);
|
||||
assert(!m.cut && m.inside && !m.wide, `shown in full and inside: ${JSON.stringify(m)}`);
|
||||
// the menu and the switch are two boxes: they stand apart, on one line
|
||||
const gap = await page.evaluate(() => {
|
||||
const p = document.querySelector("#privacyModelRow .pm-model").getBoundingClientRect(), s = document.querySelector("#privacyModelRow .segs").getBoundingClientRect();
|
||||
return { gap: s.left - p.right, mid: Math.abs(p.top + p.height / 2 - (s.top + s.height / 2)) };
|
||||
});
|
||||
assert(gap.gap >= 6 && gap.gap <= 12 && gap.mid <= 1, `the menu stands apart from the switch: ${JSON.stringify(gap)}`);
|
||||
const before = await page.evaluate(() => [scrollX, scrollY, document.querySelector("#view-settings").scrollTop]);
|
||||
await pick.click();
|
||||
const menu = page.locator(".proto-menu");
|
||||
|
||||
@@ -8,6 +8,8 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/gwmw"
|
||||
"github.com/yetone/magpie/internal/pii"
|
||||
@@ -37,8 +39,37 @@ func optionsCtx(ctx context.Context) redact.Options {
|
||||
return o
|
||||
}
|
||||
|
||||
// picked is the local model st has masking use; a var for tests.
|
||||
var picked = func(st settings.Settings) pii.Model { return pii.Of(pii.Choose(st.RedactModelName, true)) }
|
||||
// picked is the local model st has masking use; a var for tests. One
|
||||
// that is Privacy Filter only because no model was picked (pii.Choose)
|
||||
// starts AstrLink Guard's download, the default, and is moved onto it
|
||||
// once that is done.
|
||||
var picked = func(st settings.Settings) pii.Model {
|
||||
id := pii.Choose(st.RedactModelName, true)
|
||||
if st.RedactModelName == "" && id == pii.PrivacyFilter {
|
||||
toGuard()
|
||||
}
|
||||
return pii.Of(id)
|
||||
}
|
||||
|
||||
// guardTried is when toGuard last started a download, so a failed one is
|
||||
// tried again an hour later rather than on every request.
|
||||
var guardTried atomic.Int64
|
||||
|
||||
// toGuard downloads AstrLink Guard, then saves it as the pick, unless the
|
||||
// user picked a model in between, and lets Privacy Filter go.
|
||||
func toGuard() {
|
||||
now := time.Now().Unix()
|
||||
if t := guardTried.Load(); t != 0 && now-t < 3600 || !guardTried.CompareAndSwap(t, now) {
|
||||
return
|
||||
}
|
||||
g := pii.Of(pii.AstrLinkGuard)
|
||||
g.Download(func() {
|
||||
if settings.Load().RedactModelName == "" && settings.UseRedactModel(pii.AstrLinkGuard) == nil {
|
||||
pii.Of(pii.PrivacyFilter).Stop()
|
||||
g.Warm()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// model is the local model m (internal/pii) as redact's Model, waited for
|
||||
// until ctx ends, keeping what it is at least min sure of. One that can't
|
||||
|
||||
@@ -10,10 +10,10 @@ import (
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
)
|
||||
|
||||
// Masking asks the model the user picked; with none picked, Privacy
|
||||
// Filter, which was the only one when the model was turned on.
|
||||
// Masking asks the model the user picked; with none picked, AstrLink
|
||||
// Guard (Privacy Filter isn't on disk in a test).
|
||||
func TestMaskingUsesThePickedModel(t *testing.T) {
|
||||
for name, want := range map[string]string{"": pii.PrivacyFilter, pii.PrivacyFilter: pii.PrivacyFilter, pii.AstrLinkGuard: pii.AstrLinkGuard} {
|
||||
for name, want := range map[string]string{"": pii.AstrLinkGuard, pii.PrivacyFilter: pii.PrivacyFilter, pii.AstrLinkGuard: pii.AstrLinkGuard} {
|
||||
if got := picked(settings.Settings{RedactModel: true, RedactModelName: name}).ID(); got != want {
|
||||
t.Errorf("picked %q: %s, want %s", name, got, want)
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ func TestChoose(t *testing.T) {
|
||||
want string
|
||||
}{
|
||||
{"", false, AstrLinkGuard}, // a new user
|
||||
{"", true, PrivacyFilter}, // had Privacy Filter on before there was a choice
|
||||
{"", true, AstrLinkGuard}, // on, Privacy Filter not downloaded
|
||||
{AstrLinkGuard, true, AstrLinkGuard}, // picked
|
||||
{PrivacyFilter, false, PrivacyFilter}, // picked
|
||||
{"something-else", false, AstrLinkGuard},
|
||||
@@ -96,8 +96,8 @@ func TestChoose(t *testing.T) {
|
||||
t.Errorf("Choose(%q, %v) = %q, want %q", c.name, c.on, got, c.want)
|
||||
}
|
||||
}
|
||||
// Privacy Filter downloaded and turned off: turning the model on
|
||||
// again uses it, rather than download another
|
||||
// Privacy Filter downloaded: turned off, AstrLink Guard is the
|
||||
// default; on, it masks until AstrLink Guard is downloaded
|
||||
os.MkdirAll(dir(), 0o755)
|
||||
os.WriteFile(modelPath(), make([]byte, 1), 0o644)
|
||||
wasSize := modelSize
|
||||
@@ -105,8 +105,11 @@ func TestChoose(t *testing.T) {
|
||||
defer func() { modelSize = wasSize }()
|
||||
os.MkdirAll(serveDir(), 0o755)
|
||||
os.WriteFile(exe("pf-serve"), []byte("x"), 0o755)
|
||||
if got := Choose("", false); got != PrivacyFilter {
|
||||
t.Errorf("with Privacy Filter on disk, Choose = %q", got)
|
||||
if got := Choose("", false); got != AstrLinkGuard {
|
||||
t.Errorf("with Privacy Filter on disk and off, Choose = %q", got)
|
||||
}
|
||||
if got := Choose("", true); got != PrivacyFilter {
|
||||
t.Errorf("with Privacy Filter on disk and on, Choose = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-6
@@ -229,17 +229,18 @@ func Of(id string) Model {
|
||||
}
|
||||
|
||||
// Choose is the model masking uses: the one the user picked (name);
|
||||
// with none picked, Privacy Filter where it was turned on (on) or
|
||||
// downloaded before there was a choice, so its user keeps the model they
|
||||
// had and downloads nothing; else AstrLink Guard, a 38 MB download that
|
||||
// runs on every CPU and, measured on code (docs/subsystems), masks far
|
||||
// fewer ordinary values.
|
||||
// with none picked, AstrLink Guard, a 38 MB download that runs on every
|
||||
// CPU and, measured on code (docs/subsystems), masks far fewer ordinary
|
||||
// values. Only while the model is on (on) and Privacy Filter is on disk
|
||||
// but AstrLink Guard isn't is it Privacy Filter, so a user who had it on
|
||||
// before there was a choice isn't held back while AstrLink Guard
|
||||
// downloads (masking.picked starts that download).
|
||||
func Choose(name string, on bool) string {
|
||||
switch name {
|
||||
case PrivacyFilter, AstrLinkGuard:
|
||||
return name
|
||||
}
|
||||
if on || Installed() {
|
||||
if on && !guardInstalled() && Installed() {
|
||||
return PrivacyFilter
|
||||
}
|
||||
return AstrLinkGuard
|
||||
|
||||
Reference in New Issue
Block a user