A-373 tools-read: a reader that cannot open a list or pass object is shown its small fields and where the rest is, so what the last pass said of the sealed list is readable

Builds: design 47 G A-373 (G-22-lead-answers-2.md), the tools' read of the keys list and pass

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-14 01:51:19 +01:00
parent 6edfe1da8d
commit 54a19f3f64
2 changed files with 33 additions and 6 deletions
@@ -29,6 +29,24 @@ type bigPointer struct {
KeptIn string `json:"kept_in_object"`
SHA256 string `json:"sha256"`
Bytes int `json:"bytes"`
// Small is the value's small fields, what a reader that cannot open the object is shown (the tools'): the pass's `sealed` and its
// errors, the list's digest and revision.
Small json.RawMessage `json:"small,omitempty"`
}
// smallFieldsOf is the fields of a JSON object value that are under 4 KiB each; nil when the value is no object.
func smallFieldsOf(value []byte) json.RawMessage {
var fields map[string]json.RawMessage
if json.Unmarshal(value, &fields) != nil {
return nil
}
for k, v := range fields {
if len(v) > 4096 {
delete(fields, k)
}
}
out, _ := json.Marshal(fields)
return out
}
// BigValues is store with the keys `list` and `pass` of the state user-list kept in objects. With no objects (the tools') a value is
@@ -51,7 +69,7 @@ func (s bigStore) Put(state, key string, value []byte) (uint64, error) {
return 0, fmt.Errorf("the value of %s could not be put as the object %s: %w", key, name, err)
}
sum := sha256.Sum256(value)
ptr, _ := json.Marshal(bigPointer{KeptIn: name, SHA256: hex.EncodeToString(sum[:]), Bytes: len(value)})
ptr, _ := json.Marshal(bigPointer{KeptIn: name, SHA256: hex.EncodeToString(sum[:]), Bytes: len(value), Small: smallFieldsOf(value)})
return s.Store.Put(state, key, ptr)
}
@@ -65,7 +83,15 @@ func (s bigStore) Get(state, key string) ([]byte, uint64, bool, error) {
return raw, rev, found, nil // a value kept whole, as before
}
if s.objects == nil {
return nil, rev, true, fmt.Errorf("the value of %s is kept in the object %s of the part's object bucket, which this reader cannot open", key, p.KeptIn)
// A reader that cannot open the object (the tools') is shown the value's small fields and where the rest is, so what a pass said of
// the sealed list is readable without the object.
var fields map[string]json.RawMessage
if json.Unmarshal(p.Small, &fields) != nil || fields == nil {
fields = map[string]json.RawMessage{}
}
fields["partial"], _ = json.Marshal(fmt.Sprintf("the rest of the value of %s is in the object %s (%d bytes), which this reader cannot open", key, p.KeptIn, p.Bytes))
out, _ := json.Marshal(fields)
return out, rev, true, nil
}
data, err := s.objects.GetObject(p.KeptIn)
if err != nil {
@@ -29,7 +29,7 @@ func (m memObjects) GetObject(name string) ([]byte, error) {
// Design 47 G A-373: the user list and the pass result, over 256 KB each, are written and read back through objects the keys name.
func TestAListOverTheBucketsValueIsKeptAsAnObject(t *testing.T) {
big := []byte(`{"v":"` + strings.Repeat("x", 450000) + `"}`)
big := []byte(`{"sealed":"held: for the test","v":"` + strings.Repeat("x", 450000) + `"}`)
for _, key := range []string{KeyList, KeyPass} {
raw := limitStore{memStore{}}
if _, err := raw.Put(StateUserList, key, big); err == nil {
@@ -44,9 +44,10 @@ func TestAListOverTheBucketsValueIsKeptAsAnObject(t *testing.T) {
if err != nil || !found || !bytes.Equal(got, big) {
t.Fatalf("%s read back: %d bytes, found %v, %v", key, len(got), found, err)
}
// The tools' reader holds no objects: it is told where the value is, never given an empty one.
if _, _, _, err := BigValues(raw, nil).Get(StateUserList, key); err == nil || !strings.Contains(err.Error(), BigObjectName(key)) {
t.Errorf("%s read with no objects: %v", key, err)
// The tools' reader holds no objects: it is shown the small fields and where the rest is, never an empty answer.
part, _, found, err := BigValues(raw, nil).Get(StateUserList, key)
if err != nil || !found || !strings.Contains(string(part), BigObjectName(key)) || !strings.Contains(string(part), `"partial"`) || !strings.Contains(string(part), "held: for the test") {
t.Errorf("%s read with no objects: %s, %v", key, part, err)
}
// A write that cannot be made stays an error.
if _, err := BigValues(raw, failingObjects{}).Put(StateUserList, key, big); err == nil {