test(environment): verify probe timestamp ordering (#11953)

This commit is contained in:
morluto authored and GitHub committed 2026-11-18 11:13:21 +08:00
1 parent 2b26bd107e
commit 27a3f5bbd3
1 file changed
+67 -92
@@ -803,52 +803,51 @@ describe("probe request chronology", () => {
],
["2026-10-20T09:00:00.0002Z", "2026-10-20T09:00:00.0001Z"],
["2026-10-20T09:00:00.0000000002Z", "2026-10-20T09:00:00.0000000001Z"],
["0001-01-01T00:00:00.0002Z", "0001-01-01T01:00:00.0001+01:00"],
["2026-10-20 09:00:00.0002Z", "2026-10-20 09:00:00.0001Z"],
["2026-10-20T10:00:00.0002+0100", "2026-10-20T09:00:00.0001Z"],
["2026-10-20 10:00:00.0002+0100", "2026-10-20 09:00:00.0001+0000"],
["2026-10-20T09:00:00.0002", "2026-10-20T09:00:00.0001"],
])(
"replays an earlier delete before a later submillisecond read (%s)",
(later, earlier) => {
const report = run(
analysisViewCaptureEvidence(
environmentManifestCaptureFixture([
{
...exchange(1, "GET", "http://app.example/api/books/2", 404),
startedDateTime: later,
response: {
status: 404,
content: {
mimeType: "application/json",
text: JSON.stringify(BOOK_NOT_FOUND),
},
["2026-10-20T09:00:00.002Z", "2026-10-20T09:00:00.001Z"],
["2026-10-20 09:00:00.0000000002Z", "2026-10-20 09:00:00.0000000001Z"],
["2026-10-20 09:00:00.0000000002", "2026-10-20T10:00:00.0000000001+01:00"],
["2026-10-20 09:01", "2026-10-20T10:00+01:00"],
])("replays an earlier delete before a later read (%s)", (later, earlier) => {
const report = run(
analysisViewCaptureEvidence(
environmentManifestCaptureFixture([
{
...exchange(1, "GET", "http://app.example/api/books/2", 404),
startedDateTime: later,
response: {
status: 404,
content: {
mimeType: "application/json",
text: JSON.stringify(BOOK_NOT_FOUND),
},
},
{
...exchange(0, "DELETE", "http://app.example/api/books/2", 204),
startedDateTime: earlier,
},
]),
),
);
if (!report.ok) throw report.error;
expect(
report.value.probes[0]?.results.map(({ ordinal, env_status }) => [
ordinal,
env_status,
},
{
...exchange(0, "DELETE", "http://app.example/api/books/2", 204),
startedDateTime: earlier,
},
]),
).toEqual([
[1, 204],
[0, 404],
]);
expect(report.value.summary).toMatchObject({
steps: 2,
equal: 2,
agreement: 1,
});
},
);
),
);
if (!report.ok) throw report.error;
expect(
report.value.probes[0]?.results.map(({ ordinal, env_status }) => [
ordinal,
env_status,
]),
).toEqual([
[1, 204],
[0, 404],
]);
expect(report.value.summary).toMatchObject({
steps: 2,
equal: 2,
agreement: 1,
});
});
it.each([
["2026-10-20T09:00:00.000100Z", "2026-10-20T10:00:00.0001+01:00"],
@@ -860,7 +859,7 @@ describe("probe request chronology", () => {
],
["Tue, 20 Oct 2026 09:00:00 GMT", "2026-10-20T09:00:00Z"],
])(
"keeps ordinal order for equal instants and native-Date spelling compatibility (%s)",
"breaks equal recorded instants by ordinal after sorting by time (%s)",
(left, right) => {
const capture = environmentManifestCaptureFixture([
{
@@ -871,10 +870,16 @@ describe("probe request chronology", () => {
...exchange(1, "GET", "http://app.example/api/books/2", 200),
startedDateTime: right,
},
{
...exchange(2, "GET", "http://app.example/api/books/3", 200),
startedDateTime: "2026-10-20T08:59:59Z",
},
]);
expect(
probeRequests(capture.records).steps.map(({ ordinal }) => ordinal),
).toEqual([0, 1]);
probeRequests(capture.records.toReversed()).steps.map(
({ ordinal }) => ordinal,
),
).toEqual([2, 0, 1]);
},
);
});
@@ -962,24 +967,31 @@ const registerProbeOrderingAndCaptureCases = () => {
it.each([undefined, "2026-02-30T09:00:00Z"])(
"keeps replay in recorded order when a start is missing or invalid: %s",
(startedDateTime) => {
const { startedDateTime: _undated, ...read } = {
...exchange(1, "GET", "http://app.example/api/books/2", 404),
response: {
status: 404,
content: {
mimeType: "application/json",
text: JSON.stringify(BOOK_NOT_FOUND),
},
},
};
const { startedDateTime: _undated, ...remove } = exchange(
0,
"DELETE",
"http://app.example/api/books/2",
204,
);
const report = run(
analysisViewCaptureEvidence(
environmentManifestCaptureFixture([
exchange(0, "DELETE", "http://app.example/api/books/2", 204),
{
...read,
...remove,
...(startedDateTime === undefined ? {} : { startedDateTime }),
},
{
...exchange(1, "GET", "http://app.example/api/books/2", 404),
// The read leads if dated requests sort first or February 30 rolls into March 2.
startedDateTime: "2026-03-01T09:00:00Z",
response: {
status: 404,
content: {
mimeType: "application/json",
text: JSON.stringify(BOOK_NOT_FOUND),
},
},
},
]),
),
);
@@ -991,43 +1003,6 @@ const registerProbeOrderingAndCaptureCases = () => {
},
);
it.each([
["2026-10-20T09:00:00.002Z", "2026-10-20T09:00:00.001Z"],
["2026-10-20 09:00:00.0000000002Z", "2026-10-20 09:00:00.0000000001Z"],
["2026-10-20 09:00:00.0000000002", "2026-10-20T10:00:00.0000000001+01:00"],
["2026-10-20 09:01", "2026-10-20T10:00+01:00"],
])(
"orders probe requests by the owner's UTC instant: %s after %s",
(readTime, writeTime) => {
const report = run(
analysisViewCaptureEvidence(
environmentManifestCaptureFixture([
{
...exchange(0, "GET", "http://app.example/api/books/2", 404),
startedDateTime: readTime,
response: {
status: 404,
content: {
mimeType: "application/json",
text: JSON.stringify(BOOK_NOT_FOUND),
},
},
},
{
...exchange(0, "DELETE", "http://app.example/api/books/2", 204),
startedDateTime: writeTime,
},
]),
),
);
if (!report.ok) throw report.error;
expect(report.value.summary).toMatchObject({ steps: 2, equal: 2 });
expect(
report.value.probes[0]?.results.map(({ ordinal }) => ordinal),
).toEqual([1, 0]);
},
);
it("refuses a browser probe that makes writes without recorded request bodies", () => {
const report = run(
scenarioCaptureEvidence(