Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dotnet/src/Generated/Rpc.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions dotnet/src/Generated/SessionEvents.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dotnet/test/Unit/SessionEventSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public class SessionEventSerializationTests
{
ShutdownType = ShutdownType.Routine,
TotalPremiumRequests = 1,
TotalApiDurationMs = TimeSpan.FromMilliseconds(100),
TotalApiDuration = TimeSpan.FromMilliseconds(100),
SessionStartTime = 1773609948932,
CodeChanges = new ShutdownCodeChanges
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { generateGoSessionEventsCode } from "../../scripts/codegen/go.ts";
import { generatePythonSessionEventsCode } from "../../scripts/codegen/python.ts";
import { generateSessionEventsCode as generateRustSessionEventsCode } from "../../scripts/codegen/rust.ts";

describe("python session event codegen", () => {
describe("session event codegen", () => {
it("maps special schema formats to the expected Python types", () => {
const schema: JSONSchema7 = {
definitions: {
Expand Down Expand Up @@ -86,6 +86,91 @@ describe("python session event codegen", () => {
expect(code).toContain("count: int");
});

it("strips Ms suffixes from duration member names while preserving JSON names", () => {
const schema: JSONSchema7 = {
definitions: {
SessionEvent: {
anyOf: [
{
type: "object",
required: ["type", "data"],
properties: {
type: { const: "session.synthetic" },
data: {
type: "object",
required: ["durationMs", "integerDurationMs", "URLMs"],
properties: {
durationMs: { type: "number", format: "duration" },
integerDurationMs: { type: "integer", format: "duration" },
optionalDurationMs: {
type: ["number", "null"],
format: "duration",
},
nullableDurationMs: {
anyOf: [
{ type: "number", format: "duration" },
{ type: "null" },
],
},
URLMs: { type: "number", format: "duration" },
},
},
},
},
],
},
},
};

const pythonCode = generatePythonSessionEventsCode(schema);

expect(pythonCode).toContain("duration: timedelta");
expect(pythonCode).toContain("integer_duration: timedelta");
expect(pythonCode).toContain("optional_duration: timedelta | None = None");
expect(pythonCode).toContain("nullable_duration: timedelta | None = None");
expect(pythonCode).toContain("urlms: timedelta");
expect(pythonCode).toContain('duration = from_timedelta(obj.get("durationMs"))');
expect(pythonCode).toContain('result["durationMs"] = to_timedelta(self.duration)');
expect(pythonCode).toContain(
'integer_duration = from_timedelta(obj.get("integerDurationMs"))'
);
expect(pythonCode).toContain(
'result["integerDurationMs"] = to_timedelta_int(self.integer_duration)'
);
expect(pythonCode).toContain(
'optional_duration = from_union([from_none, from_timedelta], obj.get("optionalDurationMs"))'
);
expect(pythonCode).toContain(
'result["optionalDurationMs"] = from_union([from_none, to_timedelta], self.optional_duration)'
);
expect(pythonCode).toContain(
'nullable_duration = from_union([from_none, from_timedelta], obj.get("nullableDurationMs"))'
);
expect(pythonCode).toContain(
'result["nullableDurationMs"] = from_union([from_none, to_timedelta], self.nullable_duration)'
);
expect(pythonCode).toContain('urlms = from_timedelta(obj.get("URLMs"))');
expect(pythonCode).toContain('result["URLMs"] = to_timedelta(self.urlms)');

const csharpCode = generateCSharpSessionEventsCode(schema);

expect(csharpCode).toContain(
'[JsonPropertyName("durationMs")]\n public required TimeSpan Duration { get; set; }'
);
expect(csharpCode).toContain(
'[JsonPropertyName("integerDurationMs")]\n public required TimeSpan IntegerDuration { get; set; }'
);
expect(csharpCode).toContain(
'[JsonPropertyName("optionalDurationMs")]\n public TimeSpan? OptionalDuration { get; set; }'
);
expect(csharpCode).toContain(
'[JsonPropertyName("nullableDurationMs")]\n public TimeSpan? NullableDuration { get; set; }'
);
expect(csharpCode).toContain(
'[JsonPropertyName("URLMs")]\n public required TimeSpan URLMs { get; set; }'
);
});
Comment thread
stephentoub marked this conversation as resolved.

it("collapses redundant callable wrapper lambdas", () => {
const schema: JSONSchema7 = {
definitions: {
Expand Down
Loading
Loading