Repository navigation
test(sdk): pass optional parameters in generated service tests - #2117
Merged
Merged
Conversation
Generated PHP, Python, Dart and Flutter service tests called each method with its required parameters only, so a method that dropped an optional parameter, or dropped a boolean one when it was false, still passed. Each test now passes every parameter the method accepts, with booleans as false, and asserts the value sent for each one; files, models, arrays and objects are asserted by key where their value is not comparable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🟢 Tier S · Ready to mergeThe PHP, Python, Dart, and Flutter service-test templates now pass optional arguments and assert the request values they send. Generation tests add coverage for optional booleans, query/body parameters, and multipart values across the generated SDKs.
📂 Walkthrough · 5
🔇 Filtered out · 1Findings Hansi considered but did not post.
Merged |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
After #2114, each generated PHP, Python, Dart and Flutter method test checks the verb, the path and the parameter names it sends. But it calls the method with its required parameters only, so a method that drops an optional parameter, or drops a boolean one when it is
false, still passes. Hansi raised this on console-python'sstorage.create_bucketin appwrite/sdk-for-console-python#22.Each generated method test now passes every parameter the method accepts and checks the value sent for each one.
Example values. Every non-path boolean is
false, so a droppedfalsefails the test. Everything else uses the values the templates already used: the spec example or the parameter name for strings,1for integers,1.0for numbers,[]for arrays,{}for objects, the first or example member for enums, a model built from its required properties, and an empty upload for files. Path booleans staytrueso the path segment isn't empty. No spec has one today.Per language:
PHP: required arguments are positional and optional ones use named arguments (
fileSecurity: false). TheMockery::onclosure still checksarray_keys($params)withassertSame, which now lists every parameter. It then checks the values withassertSame($expected, array_intersect_key($params, $expected)).$expectedcovers every parameter except files, which the SDK turns into aPart, and models, which::from()builds as a new instance on each call. Enums are cached instances, soassertSameworks on them. Optional enums, models andInputFileare now imported.Python: optional parameters are keyword arguments (
file_security=False). The test compares the whole request withassertEqual:parse_qs(url.query)against{'name': ['value']}, including the security query (project: ['']).{'name': 'value'}. A file's content is the empty upload.Booleans arrive as
'false'in a query string or form part.Dart/Flutter: every parameter is a named argument. The name now uses the service's own identifier (
caseCamel | overrideIdentifier, e.g.xasync).expect(params.keys, unorderedEquals(...))becomesexpect(params, {...}), which checks the exact key set and the scalar values. Enums are compared as.value. Files, arrays and objects useisA<InputFile>(),isA<List>()andisA<Map>(). For webAuth methods, the test also checks each scalar parameter inurl.queryParameters.Unchanged from #2114: config-filled path parameters, deprecated-method skipping in PHP, chunked uploads, and webAuth/location handling. Each method still gets one test, so the test count doesn't change.
Evidence
New Generation test fails before and passes after.
GenerationTest::testServiceTestsPassOptionalParametershas 13 cases. They cover the arguments and the asserted values forfunctions.createExecution(optionalasync: false) andgeneral.getOptional(optional query parameters) in all four languages, plus the Python multipart case.Tests: 22, Assertions: 22, Failures: 16.All 13 new cases fail. The other 3 aretestServiceTestsAssertTheRequestfragments (python body,dart params,flutter params), which I updated to the new assertion form.OK (22 tests, 22 assertions).Mutation check. I mutated a method in each generated fixture SDK and ran only that method's generated test:
Functions::createExecutionsendsasynconly when truthy (if ($async))General::getOptionalnever sendsnamecreate_executionsendsasynconly when truthy (if xasync:)get_optionalnever sendsnamecreateExecutionsendsasynconly whentruegetOptionalnever sendsnamegetOptionalnever sendsnameThe client fixture has no optional boolean, so Flutter has no boolean row. Its template matches Dart's.
On the real 2.4.x console spec, I changed Python's
storage.create_bucketto sendfileSecurityonly when it's truthy.test_create_bucketpasses on main and fails with this PR. This is the bug class from appwrite/sdk-for-console-python#22.Generated tests pass on the real Appwrite 2.4.x spec, generated locally:
OK (945 tests, 3525 assertions). On main it was 945 tests and 2765 assertions.1070 passed, andblack --checkpasses.+1307: All tests passed!.dart analyze testreports no new issues.+200: All tests passed!(test/services)On the fixture, PHP (
217 tests, 617 assertions), Python (159 passed), Dart (+56) and Flutter (+55) all pass.Known limits
[]/{}arguments, so GET and multipart expectations leave out array and object parameters. JSON bodies include them.🤖 Generated with Claude Code