PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: filerjs/filer (js)

Issue:
Add test for fs.open() with O_WRITE + O_EXCLUSIVE and existing file
https://codecov.io/gh/filerjs/filer/src/master/src/filesystem/implementation.js#L594 is a branch we don't test.  To hit it, I think we need:

* add a test to `fs.open.spec.js`
* `mkdir` a directory `/tmp` then create a file in the directory, `/tmp/file`
* now try to `fs.open()` that path and use the `'wx'` flag
* expect an `ENOENT` error to be returned

Somewhat similar to the structure of [this test](https://github.com/filerjs/filer/blob/master/tests/spec/fs.open.spec.js#L50).

Pull request:
add test for fs.open with wx flag for existing file
Fixes #623

Patch:
diff --git a/src/filesystem/implementation.js b/src/filesystem/implementation.js
index 725097b..b5a8f8b 100644
--- a/src/filesystem/implementation.js
+++ b/src/filesystem/implementation.js
@@ -620,7 +620,7 @@ function open_file(context, path, flags, mode, callback) {
       directoryData = result;
       if(directoryData.hasOwnProperty(name)) {
         if(flags.includes(O_EXCLUSIVE)) {
-          callback(new Errors.ENOENT('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path));
+          callback(new Errors.EEXIST('O_CREATE and O_EXCLUSIVE are set, and the named file exists', path));
         } else {
           directoryEntry = directoryData[name];
           if(directoryEntry.type === NODE_TYPE_DIRECTORY && flags.includes(O_WRITE)) {


Test patch:
diff --git a/tests/spec/fs.open.spec.js b/tests/spec/fs.open.spec.js
index edb7bc8..819b1ba 100644
--- a/tests/spec/fs.open.spec.js
+++ b/tests/spec/fs.open.spec.js
@@ -47,6 +47,23 @@ describe('fs.open', function() {
     });
   });
 
+  it('should return an error when flagged for write and the path exists', function(done) {
+    var fs = util.fs();
+
+    fs.mkdir('/tmp', function(error) {
+      if(error) throw error;
+      fs.writeFile('/tmp/file', 'data', function(error) {
+        if(error) throw error;
+        fs.open('/tmp/file', 'wx', function(error, result) {
+          expect(error).to.exist;
+          expect(error.code).to.equal('EEXIST');
+          expect(result).not.to.exist;
+          done();
+        });
+      });
+    });
+  });
+
   it('should return an error when flagged for append and the path is a directory', function(done) {
     var fs = util.fs();