Repository navigation
every version for six more spec adapters; living pages by Wayback capture (I19.8, I19.11) #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,031
−34
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| package notices | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/patch-it-dev/patch-it-plugins/core/kit/kittest" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/plugin" | ||
| "github.com/patch-it-dev/patch-it-plugins/core/versions" | ||
| "github.com/patch-it-dev/patch-it-plugins/plugins/notices/retire" | ||
| ) | ||
|
|
||
| // A year of a living page from its Web Archive captures alone: four | ||
| // captures, two of them the same content, are three versions; reading each | ||
| // and extracting each consecutive pair gives every retirement once, each | ||
| // citing the capture where it first appeared. Nothing reaches the network: | ||
| // the CDX answer and the captures are served from memory. | ||
| func TestBackfillAYearFromCaptures(t *testing.T) { | ||
| full, err := os.ReadFile("retire/testdata/openai-deprecations.md") | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| lines := strings.SplitAfter(string(full), "\n") | ||
| header := strings.Join(lines[:2], "") | ||
| // The page as it grew: the oldest capture has the sections from the | ||
| // 2026-04-22 announcement down, the next adds three, the newest is today's. | ||
| older := header + strings.Join(lines[34:], "") | ||
| middle := header + strings.Join(lines[10:], "") | ||
| pg := retire.OpenAI | ||
| capture := func(ts string) string { return "https://web.archive.org/web/" + ts + "id_/" + pg.URL } | ||
| captures := map[string]string{ | ||
| capture("20250115000000"): older, | ||
| capture("20250601000000"): middle, | ||
| capture("20251201000000"): string(full), | ||
| } | ||
| cdx := fmt.Sprintf(`[["timestamp","original","digest"], | ||
| ["20250115000000",%[1]q,"A"],["20250301000000",%[1]q,"A"],["20250601000000",%[1]q,"B"],["20251201000000",%[1]q,"C"]]`, pg.URL) | ||
| env := plugin.Env{ | ||
| Baselines: kittest.NewMem(), | ||
| Now: func() time.Time { return kittest.Clock }, | ||
| Get: func(_ context.Context, u string) ([]byte, error) { | ||
| if strings.HasPrefix(u, versions.Wayback+"/cdx/search/cdx?") { | ||
| return []byte(cdx), nil | ||
| } | ||
| if body, ok := captures[u]; ok { | ||
| return []byte(body), nil | ||
| } | ||
| t.Errorf("fetched %s", u) | ||
| return nil, fmt.Errorf("no saved copy of %s", u) | ||
| }, | ||
| } | ||
| ctx := context.Background() | ||
| p := Plugin{Page: pg} | ||
| vs, err := p.ListVersions(ctx, env) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(vs) != 3 || vs[0].ID != "2025-01-15" || vs[2].ID != "2025-12-01" { | ||
| t.Fatalf("versions %v", vs) | ||
| } | ||
| var snaps []plugin.Snapshot | ||
| for _, v := range vs { | ||
| s, err := p.ReadAt(ctx, env, v) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| snaps = append(snaps, s) | ||
| } | ||
| firstSeen := map[string]string{} // fingerprint -> the capture it's cited from | ||
| for i := range snaps { | ||
| var from plugin.Snapshot | ||
| if i > 0 { | ||
| from = snaps[i-1] | ||
| } | ||
| res, err := p.Extract(ctx, env, from, snaps[i]) | ||
| if err != nil || len(res.Rejected) > 0 { | ||
| t.Fatalf("%v %v", err, res.Rejected) | ||
| } | ||
| if len(res.Events) == 0 { | ||
| t.Errorf("%s: no new retirement", vs[i].ID) | ||
| } | ||
| for _, e := range res.Events { | ||
| if _, dup := firstSeen[e.Fingerprint]; dup { | ||
| t.Errorf("%s: %s again", vs[i].ID, e.Subject.Name) | ||
| } | ||
| if e.SourceURL != vs[i].URL { | ||
| t.Errorf("%s cites %s, want %s", e.Subject.Name, e.SourceURL, vs[i].URL) | ||
| } | ||
| firstSeen[e.Fingerprint] = e.SourceURL | ||
| } | ||
| } | ||
| // Today's page, read in one go, holds every retirement the history found | ||
| // (a retirement can only change its fingerprint, never vanish). | ||
| today, err := p.Extract(ctx, env, plugin.Snapshot{}, snaps[2]) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| for _, e := range today.Events { | ||
| if _, ok := firstSeen[e.Fingerprint]; !ok { | ||
| t.Errorf("%s on today's page, never seen in the history", e.Subject.Name) | ||
| } | ||
| } | ||
| if strings.Contains(firstSeen[today.Events[0].Fingerprint], "20250115") { | ||
| t.Errorf("today's newest retirement is cited from the oldest capture") | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking:
RunusesShapeGuardto refuse a read with far fewer notices, butExtractdoesn't. Archived captures sometimes hold a challenge or JS-shell page (still HTTP 200), soFindreads 0 notices from them. If one of those falls between two good captures, the next pair sees every notice as new and emits all of them again, citing the later capture. The fingerprints are the same, so a consumer that dedupes by fingerprint will be fine. Still, an option is to treat afromwhose read fails the shape guard as unreadable: skip the pair, or compare against the last good snapshot.