Skip to content

Commit b0572ce

Browse files
committed
fix(): release prep
1 parent 4486833 commit b0572ce

10 files changed

Lines changed: 344 additions & 11 deletions

File tree

‎api/os.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import ipc, { primordials } from './ipc.js'
1414
import { toProperCase } from './util.js'
1515
import constants from './os/constants.js'
16-
import { HOME } from './path/well-known.js'
16+
import { HOME, TMP } from './path/well-known.js'
1717

1818
export { constants }
1919

@@ -281,10 +281,11 @@ export function tmpdir () {
281281
// derive default
282282
if (!path) {
283283
if (platform() === 'ios') {
284-
// @TODO(jwerle): use a path module
285-
path = [primordials.cwd, 'tmp'].join('/')
284+
// The bundle's working directory is separate from its writable container.
285+
path = TMP || '/tmp'
286286
} else if (platform() === 'android') {
287-
path = '/data/local/tmp'
287+
// /data/local/tmp belongs to the adb shell; apps use their cache directory.
288+
path = TMP || '/data/local/tmp'
288289
} else {
289290
path = '/tmp'
290291
}

‎src/runtime/bridge/bridge.cc‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ export * from '{{url}}'
320320
};
321321

322322
const auto size = request->body.size();
323-
const auto invoked = this->router.invoke(message, request->body.shared(), size, [=](ipc::Result result) {
323+
const auto respond = [=](ipc::Result result) {
324324
if (!request->isActive()) {
325325
return;
326326
}
@@ -440,6 +440,18 @@ export * from '{{url}}'
440440
callback(*response);
441441
delete response;
442442
response = nullptr;
443+
};
444+
445+
const auto invoked = this->router.invoke(message, request->body.shared(), size, [=, this](ipc::Result result) {
446+
#if ORO_RUNTIME_PLATFORM_WINDOWS
447+
// Native services can reply from the libuv thread. WebView2 response
448+
// objects must be created on the UI thread that owns the WebView.
449+
this->dispatch([respond, result]() {
450+
respond(result);
451+
});
452+
#else
453+
respond(result);
454+
#endif
443455
});
444456

445457
if (!invoked) {

‎src/runtime/filesystem/resource.cc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ namespace oro::runtime::filesystem {
153153

154154
bool Resource::isDirectory (const Path& resourcePath) {
155155
#if ORO_RUNTIME_PLATFORM_ANDROID
156+
// AAssetManager_openDir also returns a handle for file paths. Check files
157+
// first so packaged HTML and modules are served without directory routing.
158+
if (Resource::isFile(resourcePath)) {
159+
return false;
160+
}
161+
156162
if (sharedAndroidAssetManager) {
157163
const auto assetPath = getRelativeAndroidAssetManagerPath(resourcePath);
158164
const auto assetDir = AAssetManager_openDir(

‎src/runtime/webview/scheme_handlers.cc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,12 @@ namespace oro::runtime::webview {
20082008

20092009
if (result == S_OK) {
20102010
cdpEmitResponseReceived(this);
2011+
} else {
2012+
debug(
2013+
"SchemeHandlers::Response: CreateWebResourceResponse failed (HRESULT 0x%08lx) for %s",
2014+
static_cast<unsigned long>(result),
2015+
this->request->str().c_str()
2016+
);
20112017
}
20122018
return result == S_OK;
20132019
#elif ORO_RUNTIME_PLATFORM_ANDROID

‎src/runtime/window/win.cc‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,8 @@ namespace oro::runtime::window {
14751475
) {
14761476
ICoreWebView2WebResourceRequest* platformRequest = nullptr;
14771477
ICoreWebView2Environment* env = nullptr;
1478-
ICoreWebView2Deferral* deferral = nullptr;
1478+
ComPtr<ICoreWebView2Deferral> deferral;
1479+
ComPtr<ICoreWebView2WebResourceRequestedEventArgs> requestArgs = args;
14791480

14801481
// get platform request and environment from event args
14811482
do {
@@ -1558,9 +1559,15 @@ namespace oro::runtime::window {
15581559
return E_FAIL;
15591560
}
15601561

1561-
const auto handled = this->bridge->schemeHandlers.handleRequest(req, [=](const auto& response) mutable {
1562-
args->put_Response(response.platformResponse);
1563-
deferral->Complete();
1562+
const auto bridge = this->bridge;
1563+
const auto handled = bridge->schemeHandlers.handleRequest(req, [bridge, requestArgs, deferral](const auto& response) {
1564+
// Stream completion may arrive on a native worker thread.
1565+
// Keep COM objects alive until the UI thread delivers the response.
1566+
ComPtr<ICoreWebView2WebResourceResponse> platformResponse = response.platformResponse;
1567+
bridge->dispatch([requestArgs, deferral, platformResponse]() {
1568+
requestArgs->put_Response(platformResponse.Get());
1569+
deferral->Complete();
1570+
});
15641571
});
15651572

15661573
if (!handled) {

‎test/src/fs/watcher-restart.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ test('fs.watch can stop and restart cleanly', async (t) => {
1717
await write(file, 'initial')
1818

1919
// first watcher
20-
const first = new fs.Watcher(file)
20+
const first = new fs.Watcher(file, { start: false })
2121
const firstEvent = new Promise((resolve) => {
2222
first.on('change', (evt, filename) => resolve({ evt, filename }))
2323
})
2424

25+
await first.start()
2526
await write(file, 'first-change')
2627
const ev1 = await Promise.race([
2728
firstEvent,
@@ -38,11 +39,12 @@ test('fs.watch can stop and restart cleanly', async (t) => {
3839
await first.close()
3940

4041
// second watcher
41-
const second = new fs.Watcher(file)
42+
const second = new fs.Watcher(file, { start: false })
4243
const secondEvent = new Promise((resolve) => {
4344
second.on('change', (evt, filename) => resolve({ evt, filename }))
4445
})
4546

47+
await second.start()
4648
await write(file, 'second-change')
4749
const ev2 = await Promise.race([
4850
secondEvent,

‎test/src/os.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { primordials } from 'oro:ipc'
22
import { test } from 'oro:test'
33
import * as os from 'oro:os'
4+
import fs from 'oro:fs/promises'
5+
import path from 'oro:path'
46

57
const archs = ['arm64', 'ia32', 'x64', 'unknown']
68
const platforms = [
@@ -103,6 +105,18 @@ test('os.tmpdir()', (t) => {
103105
t.ok(os.tmpdir().length > 0, 'tmpdir length > 0')
104106
})
105107

108+
test('os.tmpdir() exists and is writable', async (t) => {
109+
const directory = await fs.realpath(os.tmpdir())
110+
t.ok((await fs.stat(directory)).isDirectory(), 'temporary directory exists')
111+
const filename = path.join(directory, `oro-os-tmpdir-${Date.now()}.txt`)
112+
await fs.writeFile(filename, 'temporary data')
113+
try {
114+
t.equal(await fs.readFile(filename, 'utf8'), 'temporary data', 'temporary files can be written and read')
115+
} finally {
116+
await fs.unlink(filename)
117+
}
118+
})
119+
106120
test('os.networkInterfaces()', (t) => {
107121
function isValidAddress (address) {
108122
return (
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import test from 'node:test'
2+
import assert from 'node:assert/strict'
3+
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
4+
import { spawnSync } from 'node:child_process'
5+
import { tmpdir } from 'node:os'
6+
import path from 'node:path'
7+
8+
const compiler = ['clang++-18', 'clang++', 'c++'].find(command =>
9+
spawnSync(command, ['--version'], { stdio: 'ignore' }).status === 0)
10+
11+
test('Android packaged files are not treated as directories', {
12+
skip: !compiler ? 'A C++ compiler is required' : false
13+
}, () => {
14+
const directory = mkdtempSync(path.join(tmpdir(), 'oro-android-asset-type-'))
15+
const source = readFileSync(new URL('../../src/runtime/filesystem/resource.cc', import.meta.url), 'utf8')
16+
const start = source.indexOf(' bool Resource::isFile (const Path& resourcePath) {')
17+
const end = source.indexOf(' bool Resource::isMountedPath (', start)
18+
assert.ok(start >= 0 && end > start)
19+
20+
// Compile the production predicates with the NDK's asset-handle behavior:
21+
// openDir returns an allocated handle even when its argument names a file.
22+
const fixture = `
23+
#include <cassert>
24+
#include <filesystem>
25+
#include <fstream>
26+
#include <string>
27+
#define ORO_RUNTIME_PLATFORM_ANDROID 1
28+
namespace fs = std::filesystem;
29+
using Path = fs::path;
30+
using String = std::string;
31+
struct AAssetManager {};
32+
struct AAsset {};
33+
struct AAssetDir {};
34+
constexpr int AASSET_MODE_BUFFER = 3;
35+
AAssetManager manager;
36+
AAssetManager* sharedAndroidAssetManager = &manager;
37+
int openAssets = 0;
38+
int openDirectories = 0;
39+
AAsset* AAssetManager_open (AAssetManager*, const char* name, int) {
40+
if (String(name) == "index.html" || String(name) == "oro/test.js") {
41+
++openAssets;
42+
return new AAsset;
43+
}
44+
return nullptr;
45+
}
46+
void AAsset_close (AAsset* asset) { --openAssets; delete asset; }
47+
AAssetDir* AAssetManager_openDir (AAssetManager*, const char*) {
48+
++openDirectories;
49+
return new AAssetDir;
50+
}
51+
void AAssetDir_close (AAssetDir* directory) { --openDirectories; delete directory; }
52+
Path getRelativeAndroidAssetManagerPath (const Path& resourcePath) { return resourcePath; }
53+
struct Resource {
54+
static bool isFile (const Path&);
55+
static bool isDirectory (const Path&);
56+
static bool isDirectory (const String&);
57+
};
58+
${source.slice(start, end)}
59+
int main () {
60+
assert(Resource::isFile(Path("index.html")));
61+
assert(!Resource::isDirectory(Path("index.html")));
62+
assert(!Resource::isDirectory(Path("oro/test.js")));
63+
assert(Resource::isDirectory(Path("oro")));
64+
assert(Resource::isDirectory(Path("")));
65+
std::ofstream("loose.txt") << "fixture";
66+
assert(!Resource::isDirectory(Path("loose.txt")));
67+
sharedAndroidAssetManager = nullptr;
68+
assert(Resource::isDirectory(Path(".")));
69+
assert(!Resource::isDirectory(Path("missing")));
70+
assert(openAssets == 0);
71+
assert(openDirectories == 0);
72+
}
73+
`
74+
const filename = path.join(directory, 'asset-type.cc')
75+
const executable = path.join(directory, process.platform === 'win32' ? 'asset-type.exe' : 'asset-type')
76+
writeFileSync(filename, fixture)
77+
const compiled = spawnSync(compiler, ['-std=c++20', filename, '-o', executable], { encoding: 'utf8' })
78+
assert.equal(compiled.status, 0, compiled.stderr)
79+
const result = spawnSync(executable, [], { cwd: directory, encoding: 'utf8' })
80+
assert.equal(result.status, 0, result.stderr)
81+
})

‎test/unit/os-tmpdir.test.js‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import test from 'node:test'
2+
import assert from 'node:assert/strict'
3+
import { copyFileSync, mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
4+
import { tmpdir } from 'node:os'
5+
import path from 'node:path'
6+
import { pathToFileURL } from 'node:url'
7+
8+
const container = '/app/data/tmp/'
9+
10+
for (const [platform, env, expected] of [
11+
['ios', {}, '/app/data/tmp'],
12+
['ios', { TMPDIR: '/custom/tmp/' }, '/custom/tmp'],
13+
['android', {}, '/app/data/tmp'],
14+
['android', { TMPDIR: '/custom/tmp/' }, '/custom/tmp'],
15+
['linux', {}, '/tmp']
16+
]) {
17+
test(`os.tmpdir uses ${expected} on ${platform}`, async () => {
18+
const directory = mkdtempSync(path.join(tmpdir(), 'oro-os-tmpdir-'))
19+
mkdirSync(path.join(directory, 'path'))
20+
mkdirSync(path.join(directory, 'os'))
21+
writeFileSync(path.join(directory, 'package.json'), '{"type":"module"}')
22+
copyFileSync(new URL('../../api/os.js', import.meta.url), path.join(directory, 'os.js'))
23+
copyFileSync(new URL('../../api/path/well-known.js', import.meta.url), path.join(directory, 'path', 'well-known.js'))
24+
writeFileSync(path.join(directory, 'ipc.js'), `
25+
export const primordials = { platform: ${JSON.stringify(platform)}, cwd: '/app/bundle/ui' }
26+
export default { sendSync () { return { data: { tmp: ${JSON.stringify(container)} } } } }
27+
`)
28+
writeFileSync(path.join(directory, 'util.js'), 'export const toProperCase = value => value\n')
29+
writeFileSync(path.join(directory, 'os', 'constants.js'), 'export default {}\n')
30+
const previousArgs = Object.getOwnPropertyDescriptor(globalThis, '__args')
31+
try {
32+
globalThis.__args = { env }
33+
const os = await import(pathToFileURL(path.join(directory, 'os.js')).href)
34+
assert.equal(os.tmpdir(), expected)
35+
assert.ok(!os.tmpdir().startsWith('/app/bundle/'))
36+
} finally {
37+
if (previousArgs) Object.defineProperty(globalThis, '__args', previousArgs)
38+
else delete globalThis.__args
39+
}
40+
})
41+
}

0 commit comments

Comments
 (0)