forked from xamarin/GoogleApisForiOSComponents
-
-
Notifications
You must be signed in to change notification settings - Fork 29
[codex] Fix Firestore GetQueryNamed runtime drift #112
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
AdamEssenmacher
merged 1 commit into
main
from
codex/runtime-drift-cloudfirestore-getquerynamed
Apr 10, 2026
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # Firebase Runtime Failure Backlog | ||
|
|
||
| This backlog tracks binding drifts that are concrete candidates for the runtime-failure remediation loop. | ||
|
|
||
| ## Ready | ||
|
|
||
| | Case id | Target/member | Audit finding reference | Expected runtime failure mechanism | Proof status | Fix PR | Merged commit | | ||
| | --- | --- | --- | --- | --- | --- | --- | | ||
| | `cloudfirestore-getquerynamed` | `Firebase.CloudFirestore.Firestore.GetQueryNamed` | `output/firebase-binding-audit/report.json` -> `CloudFirestore` -> `GetQueryNamed` (`signature-drift`) | The binding currently exports `getQueryNamed:completion:` as `NSInputStream` instead of `NSString`, so native Firestore receives `__NSCFInputStream` and throws an Objective-C exception when it treats the argument like a string. | Proved locally on the unfixed binding. Evidence: `ObjCRuntime.ObjCException`, `NSInvalidArgumentException`, selector `-[__NSCFInputStream length]`, artifact `tests/E2E/Firebase.Foundation/artifacts/firebase-foundation-result-cloudfirestore-getquerynamed-failure.json`, log `tests/E2E/Firebase.Foundation/artifacts/firebase-foundation-sim-cloudfirestore-getquerynamed-failure.log`. | Pending | - | | ||
|
|
||
| ## Investigating | ||
|
|
||
| No additional runtime-failure candidates are currently promoted. | ||
|
|
||
| ## Done | ||
|
|
||
| None yet. |
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
143 changes: 143 additions & 0 deletions
143
tests/E2E/Firebase.Foundation/FirebaseFoundationE2E/FirebaseRuntimeDriftCases.cs
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,143 @@ | ||
| using System.Reflection; | ||
|
|
||
| #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED | ||
| using Firebase.CloudFirestore; | ||
| using Foundation; | ||
| using ObjCRuntime; | ||
| #endif | ||
|
|
||
| namespace FirebaseFoundationE2E; | ||
|
|
||
| static class FirebaseRuntimeDriftCases | ||
| { | ||
| static readonly TimeSpan AsyncTimeout = TimeSpan.FromSeconds(5); | ||
|
|
||
| public static string? GetConfiguredCaseId() | ||
| { | ||
| return GetAssemblyMetadataValue("RuntimeDriftCase"); | ||
| } | ||
|
|
||
| public static async Task<string> ExecuteConfiguredCaseAsync() | ||
| { | ||
| var caseId = GetConfiguredCaseId(); | ||
| if (string.IsNullOrWhiteSpace(caseId)) | ||
| { | ||
| throw new InvalidOperationException("Runtime drift mode was requested without a RuntimeDriftCase value."); | ||
| } | ||
|
|
||
| var methodName = GetAssemblyMetadataValue("RuntimeDriftCaseMethod"); | ||
| if (string.IsNullOrWhiteSpace(methodName)) | ||
| { | ||
| throw new InvalidOperationException($"Runtime drift case '{caseId}' is missing RuntimeDriftCaseMethod metadata."); | ||
| } | ||
|
|
||
| var method = typeof(FirebaseRuntimeDriftCases).GetMethod(methodName, BindingFlags.Static | BindingFlags.NonPublic); | ||
| if (method is null) | ||
| { | ||
| throw new InvalidOperationException($"Runtime drift case '{caseId}' points at missing method '{methodName}'."); | ||
| } | ||
|
|
||
| if (method.Invoke(null, null) is not Task<string> task) | ||
| { | ||
| throw new InvalidOperationException($"Runtime drift case '{caseId}' method '{methodName}' did not return Task<string>."); | ||
| } | ||
|
|
||
| return await task; | ||
| } | ||
|
|
||
| static string? GetAssemblyMetadataValue(string key) | ||
| { | ||
| return typeof(FirebaseRuntimeDriftCases) | ||
| .Assembly | ||
| .GetCustomAttributes<AssemblyMetadataAttribute>() | ||
| .FirstOrDefault(attribute => string.Equals(attribute.Key, key, StringComparison.Ordinal)) | ||
| ?.Value; | ||
| } | ||
|
|
||
| #if ENABLE_RUNTIME_DRIFT_CASE_CLOUDFIRESTORE_GETQUERYNAMED | ||
| static async Task<string> VerifyCloudFirestoreGetQueryNamedAsync() | ||
| { | ||
| const string selector = "getQueryNamed:completion:"; | ||
|
|
||
| var firestore = Firestore.SharedInstance; | ||
| if (firestore is null) | ||
| { | ||
| throw new InvalidOperationException("Firebase.CloudFirestore.Firestore.SharedInstance returned null after App.Configure()."); | ||
| } | ||
|
|
||
| var queryName = "codex-firestore-missing-query"; | ||
| var callbackInvoked = false; | ||
| var returnedQueryWasNull = false; | ||
| NSException? marshaledException = null; | ||
| MarshalObjectiveCExceptionMode? marshaledExceptionMode = null; | ||
| var completionSource = new TaskCompletionSource<Query?>(TaskCreationOptions.RunContinuationsAsynchronously); | ||
|
|
||
| void OnMarshalObjectiveCException(object? sender, MarshalObjectiveCExceptionEventArgs args) | ||
| { | ||
| marshaledException ??= args.Exception; | ||
| marshaledExceptionMode ??= args.ExceptionMode; | ||
| } | ||
|
|
||
| Runtime.MarshalObjectiveCException += OnMarshalObjectiveCException; | ||
| try | ||
| { | ||
| try | ||
| { | ||
| firestore.GetQueryNamed(queryName, query => | ||
| { | ||
| callbackInvoked = true; | ||
| returnedQueryWasNull = query is null; | ||
| completionSource.TrySetResult(query); | ||
| }); | ||
| } | ||
| catch (ObjCException ex) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Selector '{selector}' should not throw after the binding fix, but observed {ex.GetType().FullName}. " + | ||
| $"Runtime argument type: {queryName.GetType().FullName}. " + | ||
| $"NSException.Name: {FormatDetail(marshaledException?.Name?.ToString())}. " + | ||
| $"NSException.Reason: {FormatDetail(marshaledException?.Reason)}. " + | ||
| $"Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}.", | ||
| ex); | ||
| } | ||
|
|
||
| var completedTask = await Task.WhenAny(completionSource.Task, Task.Delay(AsyncTimeout)); | ||
| if (completedTask != completionSource.Task) | ||
| { | ||
| throw new TimeoutException( | ||
| $"Selector '{selector}' did not invoke its completion callback within {AsyncTimeout.TotalSeconds} seconds after the binding fix."); | ||
| } | ||
|
|
||
| var returnedQuery = await completionSource.Task; | ||
| if (!callbackInvoked) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Selector '{selector}' completed without throwing, but the completion callback was never marked as invoked."); | ||
| } | ||
|
|
||
| if (marshaledException is not null) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Selector '{selector}' completed, but Runtime.MarshalObjectiveCException captured unexpected NSException.Name '{marshaledException.Name}'. " + | ||
| $"Reason: {FormatDetail(marshaledException.Reason)}. Marshal mode: {FormatDetail(marshaledExceptionMode?.ToString())}."); | ||
| } | ||
|
|
||
| return | ||
| $"Selector '{selector}' completed without ObjC exception after the binding fix. " + | ||
| $"Runtime argument type: {queryName.GetType().FullName}. " + | ||
| $"CallbackInvoked: {callbackInvoked}. " + | ||
| $"ReturnedQueryWasNull: {returnedQueryWasNull}. " + | ||
| $"ReturnedQueryType: {returnedQuery?.GetType().FullName ?? "<null>"}."; | ||
| } | ||
| finally | ||
| { | ||
| Runtime.MarshalObjectiveCException -= OnMarshalObjectiveCException; | ||
| } | ||
| } | ||
| #endif | ||
|
|
||
| static string FormatDetail(string? value) | ||
| { | ||
| return string.IsNullOrWhiteSpace(value) ? "<empty>" : value; | ||
| } | ||
| } |
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,15 @@ | ||
| { | ||
| "cases": [ | ||
| { | ||
| "id": "cloudfirestore-getquerynamed", | ||
| "method": "VerifyCloudFirestoreGetQueryNamedAsync", | ||
| "bindingPackage": "AdamE.Firebase.iOS.CloudFirestore", | ||
| "packages": [ | ||
| { | ||
| "id": "AdamE.Firebase.iOS.CloudFirestore", | ||
| "version": "12.6.0" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.